[英]Carry Flag Compare, when is the carry flag set?
The assembler has this code: 汇编器具有以下代码:
sub$0x22,%eax # %eax = %eax - 22
cmp$0x7,%eax # %eax > 7 then jump *this is where I have trouble*
ja some address # jump if C = 1 or Z = 1
My goal is to not make the jump. 我的目标是不跳。 I have tried the cases where %eax = 30, 14, 28, 16, 0 , 22
我已经尝试过%eax = 30、14、28、16、0、22的情况
Question: I don't understand why c=0 and z=0 with all the cases I have tried. 问题:在我尝试过的所有情况下,我都不明白为什么c = 0和z = 0。
0x22
, which is 34 decimal, is larger than all of those sample eax values (assuming they're decimal). 0x22
(十进制为34)大于所有这些示例eax值(假设它们为十进制)。 Thus, the result of the subtraction is negative. 因此,相减的结果为负。 But a "negative" integer is just an integer where the most significant bit is a 1, and can also be interpreted as a large unsigned number.
但是“负”整数只是一个最高有效位为1的整数,也可以解释为一个大的无符号数。
It's probably easier to think of ja
in terms of what it means conceptually rather than the actual logic on the flags. 从概念上讲
ja
可能更容易想到ja
,而不是标志上的实际逻辑。 ( see this answer ) You can think of ja
as an unsigned comparison. ( 请参阅此答案 )您可以将
ja
视为无符号比较。 So those negative numbers look like really big numbers that are larger than 7. If you used a jg
instruction instead, it should behave more like what you're expecting. 因此,那些负数看起来确实是大于7的大数。如果您改用
jg
指令,则其行为应与您期望的一样。 It can be thought of as a signed comparison. 可以将其视为经过签名的比较。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.