Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 6th, 2006, 11:47 PM   #1
eax
Newbie
 
eax's Avatar
 
Join Date: Mar 2006
Posts: 17
Rep Power: 0 eax is on a distinguished road
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
eax is offline   Reply With Quote
Old Apr 7th, 2006, 4:04 PM   #2
Narue
Professional Programmer
 
Narue's Avatar
 
Join Date: Sep 2005
Posts: 419
Rep Power: 3 Narue is on a distinguished road
>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.
Narue is offline   Reply With Quote
Old Apr 8th, 2006, 11:50 AM   #3
eax
Newbie
 
eax's Avatar
 
Join Date: Mar 2006
Posts: 17
Rep Power: 0 eax is on a distinguished road
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:
Originally Posted by Narue
>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:
eax is offline   Reply With Quote
Old Apr 8th, 2006, 12:16 PM   #4
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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
DaWei is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:29 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC