开发者

MASM32 string comparsion

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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜