Comparison
instructions

 

CMN : Compare Negative

  CMN<suffix>  <op 1>, <op 2>

                status = op_1 - (- op_2)
CMN is the same as CMP, except it allows you to compare against small negative values (the logical NOT of operand two) that would be hard to implement otherwise; such as -1 to end a list.
So to compare with -1 we would use:
  CMN     R0, #1                  ; Compare R0 with -1
Refer also to the details for the CMP instruction.

 

 

CMP : Compare

  CMP<suffix>  <op 1>, <op 2>

                status = op_1 - op_2
CMP allows you to compare the contents of a register with another register or an immediate value, updating the status flags to allow conditional execution to take place.
It performs a subtraction, but does not store the result anywhere. Instead, the flags are updated as appropriate.
The flags refer to operand one compared against operand two. Thus, the GT suffix will be executed if operand one is greater than operand two.
Obviously you do not need to explicitly specify the S suffix as the point of the command is to update the status flags... If you do specify it, it will be ignored.

 

 

TEQ : Test Equivalence

  TEQ<suffix>  <op 1>, <op 2>

                Status = op_1 EOR op_2
TEQ is similar to TST. The difference is that the notional arithmetical calculation is an EOR rather than an AND.
This provides a way to see if bits in both operands are the same or not without affecting the Carry flag (unlike CMP).
TEQ is also used with the P suffix to alter the flags in R15 (in 26-bit mode). Refer to psr.html for more details, or go here for how to do it in 32-bit mode.

 

 

TST : Test bits

  TST<suffix>  <op 1>, <op 2>

                Status = op_1 AND op_2
TST, like CMP, does not produce a result to be placed into a destination register. Instead it performs an operation on the two operands given and reflects the result of this in the status flags.
TST is used to see if a particular bit is set. Operand one is the data word to test and operand two is a bit mask. After testing, the Zero flag will be set upon a match, or otherwise clear.
Like CMP, it does not matter if you specify the S suffix or not.
  TST     R0, #%1                 ; Test if bit zero is set in R0

 

 


Return to assembler index
Copyright © 2001 Richard Murray