btc
Bit test and complement
Copies the selected bit into CF, then complements that bit in the operand.
386 and latertakes lock
- ● set from the result
- ? undefined afterwards
- – not changed
Forms
Operands
r/m- A general-purpose register or memory location matching the operation’s size, for example
raxorqword [rbp-8]. The byte registersah,bh,chanddhcannot be used with a REX prefix, including when the memory address usesr8–r15. reg- A general-purpose register matching the operation’s size, for example
al,ax,eaxorrax. The byte registersah,bh,chanddhcannot be used with a REX prefix, which is required byspl,bpl,sil,dilandr8–r15. imm8- An 8-bit immediate,
-128to255. Instructions that sign-extend it to a wider operand interpret the byte as-128to127; shift counts do not use this sign extension.
bt leaves the operand unchanged; btc complements that bit, btr clears it and bts sets it.
For a register operand, the index wraps modulo its width: 16, 32 or 64 bits, so bt rax, 63 tests the top bit of rax. For a memory operand, a register index is a signed bit offset into a bit string and can select a bit outside the first word, doubleword or quadword. An immediate index is one byte, and the processor takes it modulo the operand width even for a memory operand. NASM encodes the number as written, so bt dword [rax], 40 tests bit 8 of the doubleword at rax. To reach a bit beyond the operand, move the address instead (bt dword [rax + 4], 8 tests bit 40 of the string) or put the index in a register.
global _start
section .text
_start:
mov rax, 12
mov rbx, 5
mov rcx, 3
mov rsi, 9
btc rax, rbx
mov rax, 60 ; syscall 60: exit
xor rdi, rdi
syscall