了解intel SUB指令 [英] Understanding intel SUB instruction
问题描述
我目前正在努力加深对汇编代码的理解,并且自从几周以来一直被看似简单的指示所困住:
I am currently trying to deepen my understanding of assembly code and I am stuck since weeks with a seemingly simple instruction :
sub al, BYTE PTR [ebp+4]
假设eax = 0x11223300
和BYTE PTR [ebp+4] = 0xaa
在上面的指令后eax
的值是什么?
Assuming eax = 0x11223300
and BYTE PTR [ebp+4] = 0xaa
what is the value of eax
after the above instruction ?
据我了解,al
仅会影响eax
中的最后一个字节(在本例中为0x00
),因此程序尝试计算0x00 - 0xaa
.但是结果是负数,我不知道结果是简单地是0x00
还是数字自动转换为负数,在这种情况下0xaa
本身可以被视为负值,这意味着我们是尝试计算0x00 - (-0x2a)
= 0x2a
From what I understand, al
can only affect the last byte in eax
(0x00
in this case) so the program tries to compute 0x00 - 0xaa
. But the result being negative, I don't get if the result would simply be 0x00
or if numbers are automatically transformed to a negative number, in which case 0xaa
can itself be considered as a negative value which would imply we are trying to compute 0x00 - (-0x2a)
= 0x2a
I found in the SUB documentation that
SUB指令执行整数减法.它评估 有符号和无符号整数操作数的结果,并设置OF 和CF标志来指示有符号或无符号结果中的溢出, 分别. SF标志指示已签名结果的符号.
The SUB instruction performs integer subtraction. It evaluates the result for both signed and unsigned integer operands and sets the OF and CF flags to indicate an overflow in the signed or unsigned result, respectively. The SF flag indicates the sign of the signed result.
但是它仅描述了标志的某些行为,在这种特殊情况下,我不知道如何查找有关这些标志的更多信息.
But it only describe some behaviour of the flags and I can't figure out how to look for more about those in such a specific case.
推荐答案
您可以通过两种不同的方式来考虑它,它们都给出相同的结果.
You can think of it in two different ways, and they both give the same result.
无符号,结果计算为256.所以0x00 – 0xaa mod 0x100 = 0x56
.
As unsigned, the result is computed mod 256. So 0x00 – 0xaa mod 0x100 = 0x56
.
如签名所示,0xaa
表示–0x56
. (不是问题中的–0x2a
.)
因此,0x00 – (–0x56) = 0x56
.
As signed, 0xaa
represents –0x56
. (Not –0x2a
as in the question.)
So, 0x00 – (–0x56) = 0x56
.
这篇关于了解intel SUB指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!