Search⌘ K

Instructions-II

Explore the functionality of TST and CMP instructions in ARM64 assembly language. Understand how these instructions set condition flags based on logical AND and subtraction operations, enabling precise register and memory comparisons during debugging. This lesson helps you differentiate their uses for bit testing and value comparison to improve program analysis and control flow understanding.

Logical compare: TST

This instruction computes the bit-wise logical AND between both operands and sets flags (including Z) according to the computed result, which is discarded.

C++
TST reg, reg
TST reg, #imm

Examples

TST   x0, #4

Suppose the x0 register contains 4 (which in binary is 100bin100_{\text{bin}})

100bin  100_{\text{bin}}\space\space AND   100bin   =  100bin\space\space100_{\text{bin}}\space\space\space = \space\space100_{\text{bin}}      !=0 \space\space\space\space\space!= 0\space (Z is cleared)

TST   w1, #1

Suppose w1 contains 00 ...