문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top