TST and TEQ

Test bits and Test Equivalence.

Show/hideSyntax

TST{cond} Rn, Operand2
TEQ{cond} Rn, Operand2

where:

cond

is an optional condition code.

Rn

is the ARM register holding the first operand.

Operand2

is a flexible second operand.

Show/hideUsage

These instructions test the value in a register against Operand2. They update the condition flags on the result, but do not place the result in any register.

The TST instruction performs a bitwise AND operation on the value in Rn and the value of Operand2. This is the same as an ANDS instruction, except that the result is discarded.

The TEQ instruction performs a bitwise Exclusive OR operation on the value in Rn and the value of Operand2. This is the same as a EORS instruction, except that the result is discarded.

Use the TEQ instruction to test if two values are equal, without affecting the V or C flags (as CMP does).

TEQ is also useful for testing the sign of a value. After the comparison, the N flag is the logical Exclusive OR of the sign bits of the two operands.

Show/hideRegister restrictions

In these Thumb instructions, you cannot use SP or PC for Rn or Operand2.

In these ARM instructions, use of SP or PC is deprecated in ARMv6T2 and above.

For ARM instructions:

  • if you use PC (R15) as Rn, the value used is the address of the instruction plus 8

  • you cannot use PC for any operand in any data processing instruction that has a register-controlled shift.

Show/hideCondition flags

These instructions:

  • update the N and Z flags according to the result

  • can update the C flag during the calculation of Operand2

  • do not affect the V flag.

Show/hide16-bit instructions

The following form of the TST instruction is available in Thumb code, and is a 16-bit instruction:

TST Rn, Rm

Rn and Rm must both be Lo registers.

Show/hideArchitectures

These ARM instructions are available in all architectures with ARM.

The TST Thumb instruction is available in all architectures with Thumb.

The TEQ Thumb instruction is available in ARMv6T2 and above.

Show/hideExamples

    TST     r0, #0x3F8
    TEQEQ   r10, r9
    TSTNE   r1, r5, ASR r1

Show/hideIncorrect example

    TEQ     pc, r1, ROR r0      ; PC not permitted with register
                                ; controlled shift

Show/hideSee also

Copyright © 2010-2011 ARM. All rights reserved.ARM DUI 0489E
Non-ConfidentialID071611