How does the `test` instruction work?
Asked Answered
B

1

6

If we have:

test dword ptr [eax], 2000h
je label1:

Is there any value other than 0 in dword ptr [eax] that would make the jump take place?

Berthaberthe answered 16/12, 2010 at 7:27 Comment(1)
No 2000h won't work I tried it, it's not cmp. However with 0 the zero flag is sat so je triggers.Berthaberthe
C
9

Instruction test works like and instruction, the only difference is that result is not stored back in to the destination operand. So the answer is yes. All binary numbers which not have set the 13th bit on memory address [eax], or all numbers present like b'xxxxxxxx xxxxxxxx xx0xxxxx xxxxxxxx', where x is 0 or 1, there is exactly 2^31 numbers.

Coventry answered 16/12, 2010 at 7:49 Comment(2)
And what does test eax, eax do?Threaten
@BlackBear: test eax, eax will set zero flag if eax = 0 the some as instruction and eax, eax (also effect to the sign and parity flags and clear carry and overflow flags).Coventry

© 2022 - 2024 — McMap. All rights reserved.