如何访问x86程序集中int变量中的特定位以检查它是0还是1?
我认为这会有用,但它不会
int main()
{
int num = 3; //stored as a 32 bit binary I assumed something like ...011
//now I need to test the 2nd bit of num
__asm
{
test num, 1 // By the way, how would I check the ZF flag?
}
}
答案 0 :(得分:0)
我假设aex
代表eax
。
如果你只想测试eax
的第0位,你可以这样做:
test eax, 1
; ZF will be set based on eax AND 1. eax remains unchanged
jnz bit0_is_set
; The jump wasn't taken, so bit 0 was clear
...
jmp done
bit0_is_set:
; The jump was taken, so bit 0 was set
...
done:
要测试其他位,请使用增加的2的幂:对于位1为2,对于位2为4,对于位3为8等。
如果你真的想将eax
的第0位复制到ebx
,你可以这样做:
mov ebx, eax
and ebx, 1