tst
Test (A32)
TST<c> <Rn>, <Operand2>
Bitwise AND and update flags (discard result).
Details
Performs a bitwise AND of Rn and Operand2, updates the condition flags based on the result, and discards the result. The N flag is set if bit 31 of the result is 1; Z is set if the result is 0; C is affected by the shifter (if applicable); V is unchanged. This instruction is useful for testing which bits are set in a register.
Pseudocode Operation
result ← Rn AND Operand2
N ← result[31]
Z ← (result == 0)
C ← shifter_carry_out
V ← V // Unchanged
Example
TST r1, r2
Encoding
Binary Layout
cond
00110
00
1
Rn
0
0
0
0
imm12
Operands
-
Rn
First source / base general-purpose register -
Operand2
Flexible second operand (register or shifted register)
Reference (Arm AArch32 ISA)
Instruction Forms
| Encoding | Instruction | ISA | Bit pattern | ||
|---|---|---|---|---|---|
| 0x03100000 | TST{<c>}{<q>} <Rn>, #<const> | A32 | cond | 00110 | 00 | 1 | Rn | 0 | 0 | 0 | 0 | imm12 | ||
| 0xF0100F00 | TST{<c>}{<q>} <Rn>, #<const> | T32 | 11110 | i | 0 | 0000 | 1 | Rn | 0 | imm3 | 1111 | imm8 | ||
| 0x01100060 | TST{<c>}{<q>} <Rn>, <Rm>, RRX | A32 | cond | 00010 | 00 | 1 | Rn | 0 | 0 | 0 | 0 | 00000 | 11 | 0 | Rm | ||
| 0x01100000 | TST{<c>}{<q>} <Rn>, <Rm> {, <shift> #<amount>} | A32 | cond | 00010 | 00 | 1 | Rn | 0 | 0 | 0 | 0 | imm5 | stype | 0 | Rm | ||
| 0x4200 | TST{<c>}{<q>} <Rn>, <Rm> | T32 | 010000 | 1000 | Rm | Rn | ||
| 0xEA100F30 | TST{<c>}{<q>} <Rn>, <Rm>, RRX | T32 | 1110101 | 0000 | 1 | Rn | 0 | 000 | 1111 | 00 | 11 | Rm | ||
| 0xEA100F00 | TST{<c>}.W <Rn>, <Rm> | T32 | 1110101 | 0000 | 1 | Rn | 0 | imm3 | 1111 | imm2 | stype | Rm | ||
| 0x01100010 | TST{<c>}{<q>} <Rn>, <Rm>, <type> <Rs> | A32 | cond | 00010 | 00 | 1 | Rn | 0 | 0 | 0 | 0 | Rs | 0 | stype | 1 | Rm |
Description
Test (immediate) performs a bitwise AND operation on a register value and an immediate value. It updates the condition flags based on the result, and discards the result.
Operation
if ConditionPassed() then
EncodingSpecificOperations();
result = R[n] AND imm32;
PSTATE.N = result<31>;
PSTATE.Z = IsZeroBit(result);
PSTATE.C = carry;
// PSTATE.V unchanged