Opcode | Encoding | 16-bit | 32-bit | 64-bit | Description |
---|---|---|---|---|---|
0F B3 /r BTR r/m16, r16 | mr | Valid | Valid | Valid | Store the bit specified in r16 from r/m16 in CF . Reset (clear) that bit in the source operand. |
0F B3 /r BTR r/m32, r32 | mr | Valid | Valid | Valid | Store the bit specified in r32 from r/m32 in CF . Reset (clear) that bit in the source operand. |
REX.W 0F B3 /r BTR r/m64, r64 | mr | N/E | N/E | Valid | Store the bit specified in r64 from r/m64 in CF . Reset (clear) that bit in the source operand. |
0F BA /6 ib BTR r/m16, imm8 | mi | Valid | Valid | Valid | Store the bit specified in imm8 from r/m16 in CF . Reset (clear) that bit in the source operand. |
0F BA /6 ib BTR r/m32, imm8 | mi | Valid | Valid | Valid | Store the bit specified in imm8 from r/m32 in CF . Reset (clear) that bit in the source operand. |
REX.W 0F BA /6 ib BTR r/m64, imm8 | mi | N/E | N/E | Valid | Store the bit specified in imm8 from r/m64 in CF . Reset (clear) that bit in the source operand. |
Encoding
Encoding | Operand 1 | Operand 2 |
---|---|---|
mr | ModRM.reg[rw] | ModRM.r/m[r] |
mi | ModRM.r/m[rw] | imm8 |
Description
The BTR
instruction selects a bit from the first source operand and stores it in CF
. The specific bit that is selected is specified in the second source operand. Afterwards, the selected bit is reset (cleared) in the source operand.
The operand size determines how many bits of the second source operand are used; Any upper bits are ignored. For example, if the operand size is 16 bits, only the lowest five bits are used in the calculation (an effective "mod 16"). In other words, attempting to access the 21st bit of a 16-bit register will only access the fifth bit (21 mod 16 ≡ 5).
Operation
public void BTR(U16 src, U16 idx)
{
EFLAGS.CF = src.Bit[idx % 16];
src.Bit[idx % 16] = 0;
}
public void BTR(U32 src, U32 idx)
{
EFLAGS.CF = src.Bit[idx % 32];
src.Bit[idx % 32] = 0;
}
public void BTR(U64 src, U64 idx)
{
EFLAGS.CF = src.Bit[idx % 64];
src.Bit[idx % 64] = 0;
}
Flags Affected
CF
(carry flag)- Set if the specified bit is set prior to being reset. Cleared otherwise.
PF
(parity flag)- Undefined.
AF
(auxiliary flag)- Undefined.
ZF
(zero flag)- Unmodified.
SF
(sign flag)- Undefined.
OF
(overflow flag)- Undefined.
Intrinsics
None. Auto-generated by compiler.
Exceptions
Real-Address Mode
#UD
- If the
LOCK
- prefix is used.
#SS(0)
- If a memory operand using the
SS
- segment has an effective address that is outside the
SS
- segment's limit.
#GP(0)
- If a memory operand (using a segment other than
SS
- ) has an effective address that is outside the segment's limit.
Virtual-8086 Mode
#UD
- If the
LOCK
- prefix is used.
#SS(0)
- If a memory operand using the
SS
- segment has an effective address that is outside the
SS
- segment's limit.
#GP(0)
- If a memory operand (using a segment other than
SS
- ) has an effective address that is outside the segment's limit.
#PF(fc)
- If a page fault occurs.
#AC(0)
- If alignment checking is enabled while the current privilege level is 3 and an unaligned memory access is made.
Protected Mode
#UD
- If the
LOCK
- prefix is used.
#SS(0)
- If a memory operand using the
SS
- segment has an effective address that is outside the
SS
- segment's limit.
#GP(0)
- If a memory operand uses a segment containing a
NULL
selector. - If a memory operand (using a segment other than
SS
) has an effective address that is outside the segment's limit.
#PF(fc)
- If a page fault occurs.
#AC(0)
- If alignment checking is enabled while the current privilege level is 3 and an unaligned memory access is made.
Compatibility Mode
#UD
- If the
LOCK
- prefix is used.
#SS(0)
- If a memory operand using the
SS
- segment has an effective address that is outside the
SS
- segment's limit.
#GP(0)
- If a memory operand uses a segment containing a
NULL
selector. - If a memory operand (using a segment other than
SS
) has an effective address that is outside the segment's limit.
#PF(fc)
- If a page fault occurs.
#AC(0)
- If alignment checking is enabled while the current privilege level is 3 and an unaligned memory access is made.
Long Mode
#UD
- If the
LOCK
- prefix is used.
#SS(0)
- If a memory operand using the
SS
segment is in non-canonical form. - If a memory operand using the
SS
segment has an effective address that is outside theSS
segment's limit.
#GP(0)
- If a memory operand (using a segment other than
SS
) is in non-canonical form. - If a memory operand uses a segment containing a
NULL
selector. - If a memory operand (using a segment other than
SS
) has an effective address that is outside the segment's limit.
#PF(fc)
- If a page fault occurs.
#AC(0)
- If alignment checking is enabled while the current privilege level is 3 and an unaligned memory access is made.