Reputation: 35
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
Question: I don't understand why c=0 and z=0 with all the cases I have tried.
Upvotes: 0
Views: 1265
Reputation: 3675
0x22
, which is 34 decimal, is larger than all of those sample eax values (assuming they're decimal). 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.
It's probably easier to think of ja
in terms of what it means conceptually rather than the actual logic on the flags. (see this answer) You can think of ja
as an unsigned comparison. 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. It can be thought of as a signed comparison.
Upvotes: 1