Egidio Caprino
Egidio Caprino

Reputation: 553

How to fetch a bit in IA32 assembly language?

How can I check if a bit in some position of a word is 1 with the IA32 assembly language?

Upvotes: 3

Views: 399

Answers (2)

DipSwitch
DipSwitch

Reputation: 5640

NASM:

bt ax, <POS> ; test if bit at position is set: 1 means carry will be set 0 means carry will be unset
adc eax, 0   ; add 0 + carry to eax

You could also use jc (jump carry set) jnc (jump carry not set)

Upvotes: 2

Jerry Coffin
Jerry Coffin

Reputation: 490108

Test, something like:

value = 000100h

mov eax, your_word
test eax, value
jnz was_set

Upvotes: 4

Related Questions