-1

I have written following code to compare two strings, one is predefined and other is taken as input from user. But everytime the program shows them as unequal. please assist me. I am using MASM32 assembler.

.data
msg1 db '***Welcome to My Program***',13,10,0
msg2 db 'Please Enter a Product: ',0
msg3 db 'You Entered Shoes: ',0
p1 db 'Shoes',0

.data?
product db 100 dup(?)
.code

start:
invoke StdOut,ADDR msg1
invoke StdOut,ADDR msg2
invoke StdIn,ADDR product,100 ; receive text input

lea    esi, p1          ; Load the buffer start address
lea    edi, product     ; Load the save buffer start address
mov    ecx, 10          ; Load the operation count
repe   cmpsb            ; Compare the byte into the buffer
jne Terminate
invoke StdOut,ADDR msg3

Terminate:
invoke ExitProcess,0
END start
Alex K.
  • 171,639
  • 30
  • 264
  • 288
M Azeem N
  • 913
  • 2
  • 10
  • 11

1 Answers1

1

I don't have the MASM32 reference to hand but from memory StdIn will also take the carriage return + line feed from hitting enter in the console and that will be reflected in the variable you read to.

MASM32 has a built in function called StripLF or something like that to deal with this. The comparison should pass after that.

For problems like this I highly recommend OllyDbg which will allow you to step your code and see the memory dump and stack.

Edit : Just found a thread on MASM32 forums demonstrating exactly what I'm describing (ignore the fact that's a bug report but hutch comments on the designated behaviour of StdIn) : http://www.masm32.com/board/index.php?PHPSESSID=b98a1a56c52fdc4c07a2bca3553302e2&topic=51.0

Mike Kwan
  • 24,123
  • 12
  • 63
  • 96
  • Thank you for your response but i dont have time to learn more things. please someone tell me how to fix this code so that it will work! – M Azeem N Jun 24 '11 at 10:21