简体   繁体   English

在汇编中,我是否使用cmp命令缺少某些内容?

[英]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. 因此,我在[ebp-2]和[ebp-4]上都设置了零,并尝试将各个字符转换为它们的真实整数值。 My problem is when I input '00' , the program does not jump to the label i specified. 我的问题是当我输入'00'时,程序无法跳转到我指定的标签。

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. 起初,我以为ax可能不会获取值,但是不,ax将获取整数的实值。我通过打印该值对其进行测试。 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. 上面的代码在我输入00时输出0,在我输入01时输出1,这意味着转换值没有问题。 Am I missing something with the cmp command? 我在cmp命令中缺少什么吗? I am still learning assembly so I don't know if i missed a point or something about the cmp command. 我仍在学习汇编语言,所以我不知道我是否错过了一点或有关cmp命令的内容。

When you write 当你写

add ax,[ebp-4]

you also add in the high byte at [ebp-3]. 您还可以在[ebp-3]处添加高字节。 This is most probably not empty. 这很可能不是空的。 I even guess it contains an 0xA value (linefeed) ... 我什至猜测它包含一个0xA值(换行符)...
A solution might be 一个解决方案可能是

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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