Write masm32 then a corresponding program that lets say if the word entered by the user is a palindrome or not.
:icon_exclaim: :icon_exclaim: :icon_exclaim: :icon_exclaim: plz
a simple solution (http://www.rent-acoder.com)
:biggrin:
There are more subtle forms of torture :P
include \masm32\MasmBasic\MasmBasic.inc ; download (http://masm32.com/board/index.php?topic=94.0)
Init
Let esi="** Masm32 is great ##"
Let edi="## taerg si 23msaM **"
.if !StringsDiffer(esi, Mirror$(edi))
PrintLine "[", esi, "] and [", edi, "] are palindromes", CrLf$
.else
PrintLine "[", esi, "] is NOT a palindrome of [", edi, "]", CrLf$
.endif
Let edi="RentACoder is a great site"
.if StringsDiffer(esi, Mirror$(edi))
PrintLine "[", esi, "] is NOT a palindrome of [", edi, "]", CrLf$
.else
PrintLine "[", esi, "] and [", edi, "] are palindromes"
.endif
Inkey "Wow, that was incredibly complicated..."
Exit
end start
Is it better to create function that check palindrome in string ;)
Only checking upper and lower half part in reversing order ;)
Quote from: qWord on January 31, 2014, 12:04:18 PM
a simple solution (http://www.rent-acoder.com)
:t
Gunther
you could use a register to point to the beginning of the string and another to point to the end (ECX and EDX maybe)
load a character from each into AL and AH
force upper or lower case
verify AL is a letter from 'A' to 'Z' - if not, exit the loop
test if AL = AH - if not, exit the loop
increment the beginning pointer and decrement the end pointer
compare pointers and loop back to "load character" as needed
you could also search around a little bit - lol
http://www.masmforum.com/board/index.php?topic=4083.msg148024#msg148024 (http://www.masmforum.com/board/index.php?topic=4083.msg148024#msg148024)
Dave,
Quote from: dedndave on January 31, 2014, 09:24:59 PM
http://www.masmforum.com/board/index.php?topic=4083.msg148024#msg148024 (http://www.masmforum.com/board/index.php?topic=4083.msg148024#msg148024)
good catch. :t
Gunther
Quote from: TWell on January 31, 2014, 09:12:10 PM
Is it better to create function that check palindrome in string ;)
Only checking upper and lower half part in reversing order ;)
That won't do it. You gave to ignore word spaces and punctuation. I do not think that I have ever seen a palindrome in which all words were themselves a palindrome (first word is the palindrome of the last, etc. Also very much language specific. Pretty good Wiki about palindromes.
Dave.
Dave's solution is a good one. Here is a quick and crude example :
include \masm32\include\masm32rt.inc
.data
teststr db 'AmoreRoma',0
msg1 db 'teststr is a palindrome.',0
msg2 db 'teststr is not a palindrome.',0
.data?
buffer db 256 dup(?)
.code
start:
invoke szRev,ADDR teststr,ADDR buffer
invoke Cmpi,ADDR teststr,ADDR buffer
mov edx,OFFSET msg1
test eax,eax
jz @f
mov edx,OFFSET msg2
@@:
invoke StdOut,edx
invoke ExitProcess,0
END start
Hi Erol,
that'll do the job for one word palindromes. But what's with a hole sentence (see reply #8)?
Gunther
Whole sentence is that after filtering and packing.
"Amore, Roma" -> "amoreroma"
("amor" "e" "roma")
EDIT: In msvcrt.dll is function _strrev()
Well, as I said my example is a quick and simple one. It will be imadhx30's preference to write a better one.
vortex (y)
give another example of palindrome except following library:
include \ masm32 \ include \ kernel32.inc
include \ masm32 \ include \ masm32.inc
include \ masm32 \ include \ msvcrt.inc
includelib \ masm32 \ lib \ masm32.lib
includelib \ masm32 \ lib \ kernel32.lib
includelib \ masm32 \ lib \ msvcrt.lib
you could create a temporary buffer on the stack...
copy the original string into the buffer, stripping out all undesirable characters
then, perform the simple loop, as Erol showed
we don't know what kind of palindromes he's looking at (numeric or alpha)
Quote from: imadhx30 on January 31, 2014, 11:30:15 AM
...
say if the word entered by the user is a palindrome or not.
...
OP's schoolwork was that originally ?
and without include files (s)he using debugger to see result as kernel32.lib is not allowed ?
Hi imadhx30,
as already said, we won't do your homework.
Gunther
Hi imadhx30,
Without the import libraries, you cannot create the final executable using the MS linker or a compatible one.