0

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,

  1. arg2 < arg1 and the operation does not have overflow
  2. 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?

4

1 回答 1

1

操作符的<>意思是“不等于!=”,即和C 中的一样。

在 if(a <= 0) 的情况下,当 arg2 <= arg1 时 jl 不应该跳转

你的条件是a >= 0,不是a <= 0。所做的jl是跳过将在 if 中执行的代码块a >= 0

即是这样的:

cmp a,0   
jl end_if  ; jump past the body of the if-statement if the condition is false,
           ; i.e. a < 0
; code that should be executed if a >= 0 goes here
; ...
end_if:
于 2013-04-30T08:26:14.837 回答