![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Mar 2006
Posts: 17
Rep Power: 0
![]() |
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 |
|
|
|
|
|
#2 |
|
Professional Programmer
![]() Join Date: Sep 2005
Posts: 419
Rep Power: 3
![]() |
>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 lea edi,[line+eax] .again: cmp edi,esi jbe .success mov al,byte [edi] cmp al,byte [esi] jne .failure inc esi dec edi jmp .again .failure: output failure jmp .done .success: output success .done:
__________________
Even if the voices aren't real, they have some pretty good ideas. |
|
|
|
|
|
#3 | |
|
Newbie
Join Date: Mar 2006
Posts: 17
Rep Power: 0
![]() |
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:
|
|
|
|
|
|
|
#4 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|