I'm just a novice at assembly programming. I have an integer a
. I was trying to understand if there was any performance difference between
if(a >= 0)
and
if(a > -1)
So, I proceeded to disassemble the above. In my x86 machine,
if(a >= 0)
Disassembles to:
cmp dword ptr [ebp-4],0
jl main+43h (00401053)
And,
if(a > -1)
Disassembles to:
cmp dword ptr [ebp-4],0FFh
jle main+43h (00401053)
I can quickly write a program that calculates CPU cycles for these programs (haven't done that yet). BUT, I now am faced with a different issue.
I understand that cmp
will perform a sub
and set the SF
, ZF
, PF
, CF
, OF
and/or AF
flags appropriately. I also understand that a jl
will check for the SF <> OF
criteria. What is the <>
operator here?
The reference I used said that jl
will load EIP
with the specified argument if, for a cmp arg2, arg1
,
- arg2 < arg1 and the operation does not have overflow
- arg2 < arg1 and the operation has an overflow
The reference also says jl
will not jump when arg2 == arg1
.
My second question is, shouldn't jl
jump when arg2 <= arg1
in the case of if(a <= 0)
and when arg2 < arg1
in the case of if(a < -1)
?
Can someone please help me understand this?