![]() |
if the character string is palindrome ?
I need to write a program : which will read in string and determine if character string is palindrome.
I came up with this code(pasted below) , but there is logic fault. Please help me with this . output prompt1 ; ask for string as input input old,32 lea esi,old lea edi,new check_process: mov al,[esi] mov [edi],al cmp [esi],[edi] je dojob jne message ;message ,string is not palindrome dojob: inc esi dec edi jmp check_process |
>lea edi,new
What's new? >je dojob >jne message ;message ,string is not palindrome There's no need for je dojob, just drop down past the jne test. :
mov esi,line |
old BYTE 32 DUP(?)
new BYTE 32 DUP(?) When i run program using code suggested by you , it give error: invalid instruction operands for code line : mov esi,line Quote:
|
You have to make up your mind how you're going to do this. You are inputting a word. What are you going to compare it to in order to determine if it's a palindrome? If you're going to compare it, front-to-back, with 'new', then you have to copy it from 'old' to 'new', backwards. If you want to copy it directly to 'new', then you may compare from the front of 'old' forwards to the back of 'new', backwards. Narue chooses to do it sensibly, compare front of 'old' to back of 'old', increment the front pointer, decrement the back pointer, and continue until the comparison fails or the pointers cross. Done. Narue didn't show the initialization for 'line', you were supposed to pick up on the fact you need to put the string there, instead of in 'old'.
Narue, you have chocolate on your tongue. |
| All times are GMT -5. The time now is 7:45 PM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC