I have the following code:
if(( a<0 ) || ( a>global_count )) //global_count is a global int
{
print error;
}
normal_flow
...
Now here's the assembler that GCC generates:
cmpl 0x0 , 0x10(%ebp) //first check
js print_error
mov 0x8(%ebp) , %eax
mov 0x8(%eax) , %eax
cmp 0x10(%ebp) , %eax //second check
jge normal_flow
print_error
I don't understand why the jge
? I see it's using mov
, instead of movl
, but I believe it should be jle
in this case or jg
if we change jump target... or am I thinking wrong here?
It's jge
because the compiler swapped both the operands and the condition. It's doing global_count >= a
. Notice that 0x10(%ebp)
is a
and %eax
is global_count
. To complicate matters further, at&t syntax itself has operands reversed.
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.