Movart
Movart

Reputation: 151

Comparing '+' sign assembly x86

I'm trying to compare argument from command line with '+'. If it is equal it should go to add: label. I'm getting three arguments 2 numbers and sign, which I want to compare. Unfornutely it comparing doesn't work.

My code:

main:
mov eax,[esp+8]
mov ecx,[eax+4]  //first argument
mov ebx,[eax+8]  //second argument
mov esi,[eax+12] //third argument
mov eax,esi 
cmp eax,'+'
je add
    jmp end

add:
//rest of code

Upvotes: 2

Views: 875

Answers (1)

Michael
Michael

Reputation: 58497

mov esi,[eax+12] //third argument
mov eax,esi 
cmp eax,'+'

What you're doing here is comparing a character (which typically is a single byte) with the 32-bit address of the string that is the third argument. That's obviously not going to match.

The appropriate comparison would be:

mov esi,[eax+12] //third argument
cmp byte [esi],'+'  ; compare the first character of the third argument with '+'

Upvotes: 5

Related Questions