I know that for example BT BX, 0
transfers the first bit of the BX
register to the carry flag CF.
Isn't the carry flag restricted to only have values of 0 and 1, because it's a flag?
Does BT
change the CF value from the first bit of the register even if it doesn't hold 0 or 1?
If someone would be able to write here how it works, it would be great!
CodePudding user response:
BT is the instruction to test if a bit is set(1
) or not(0
). Hence it can only return two values, one or zero, which fit into a (E)FLAG value that can be either TRUE(1
) or FALSE(0
).
So BT
directly copies this bit into the CarryFlag.
The position of the desired bit is given with the immediate value at the end of the instruction - here it is 0
, meaning the lowest bit in BX
.
(BT
does not change the bit tested. For that purpose, you should use BTC, BTR and BTS.)
CodePudding user response:
Yes, the Carry flag can have one of only two possible values: 0 or 1.
So does any bit of any register, for instance the least significant bit Nr.0 of BX
.
Its value is copied by BT BX,0
to CF; BTW this can be used to test if the number in BX
is odd or even:
BT BX,0
JC Odd
Even: