Question

I'm wondering whether if the test instruction can be used the same as cmp. Let's say:

cmp %eax,%ebx
jg some_random_place

That jumps to some_random_place provided that %ebx is bigger than %eax, now if I do:

test %eax, %ebx
jg some_random_place

Under which conditions does that jump?

Was it helpful?

Solution

No!

The cmp %eax,%ebx instuction is like sub %eax,%ebx instruction, but with cmp instruction the registers after execution remain unchanged, except the flag register.

The test %eax,%ebx instuction is like and %eax,%ebx instruction, but with test instruction the registers after execution remain unchanged, except the flag register. The affected flags are Carry = 0, Zero = x, Overflow=0 and Sign = x

The jg instructon should execute jump if zero flag = 0 and sign flag = overflow

So in case...

test %eax, %ebx
jg some_random_place

...the jump should be executed if the result of and %eax,%ebx is positive and not 0.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top