简体   繁体   中英

In Assembly, Am I missing something with the cmp command?

So I place zero both on [ebp-2] and [ebp-4] and i try to convert the separate characters to their real integer values. My problem is when I input '00' , the program does not jump to the label i specified.

sub byte[ebp-2],30h   ; convert characters to integer
sub byte[ebp-4],30h
mov al,10       ;multiply by 10 for the tens value
mul byte[ebp-2] 
add ax,[ebp-4] ; add the ones to the computed tens value which is contained in ax
cmp ax,0
je cond_while1

At first, i thought ax might not be getting the value but no, ax gets the real value of the integer .I test it by printing the value. Here is how I test it:

mov [ebp+4],ax
add byte[ebp+4],30h  ;convert it back to character
mov eax,4  ;print it out
mov ebx,1
lea ecx,[ebp+4]
mov edx,1
int 80h

The code above prints 0 when i input 00 and 1 when i input 01 which means there is nothing wrong with me converting the values. Am I missing something with the cmp command? I am still learning assembly so I don't know if i missed a point or something about the cmp command.

When you write

add ax,[ebp-4]

you also add in the high byte at [ebp-3]. This is most probably not empty. I even guess it contains an 0xA value (linefeed) ...
A solution might be

movzx bx,[ebp-4]
add ax,bx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM