btst
Test a bit
Tests the bit in the second operand numbered by the first operand and sets Z to the inverse of its value.
Sizes .b .l
Used in
- Arithmetic, logic and bitsM68K assembly
- The screen, keyboard and mouse through trapsM68K assembly
- Bit tests, shifts, masks and counting set bitsM68K assembly
- Move a square with the keyboardM68K assembly
- The snake gameM68K assembly
- Flappy ASMM68K assembly
- Sampled soundM68K assembly
- Arithmetic, logic and bitsAssembly basics
XNZVC ––●––
- ● depends on the result
- – not changed
Forms
Operands
<ea>- An operand using one of the addressing modes listed for this form. The list determines whether it can be a register, memory or an immediate value. With
opt p=68020, an allowedd(An,Xn)ord(PC,Xn)mode also permits the corresponding 68020 indexed and memory indirect forms. See 68020 addressing. More #imm- An immediate value. As the first operand, it selects a bit:
0to31for a data register, or0to7for memory. More
* --- Z flag reflects the ORIGINAL bit value ---
move.l #%0101, d0
btst #0, d0 ; bit 0 = 1, Z flag clear
move.l #%0101, d1
btst #1, d1 ; bit 1 = 0, Z flag set
* --- Test higher bits ---
move.l #$80000000, d2
btst #31, d2 ; bit 31 = 1, Z flag clear