6.2.1. Arithmetic and logical operations

Table 6.1 shows some of the available arithmetic and logical operations.

Table 6.1. Arithmetic and logical operations

ArithmeticADD, SUB, ADC, SBC, NEG
Comparison CMP, CMN, TST

Some instructions also have an S suffix, indicating that the instruction sets flags. Of the instructions in Table 6.1, this includes ADDS, SUBS, ADCS, SBCS, ANDS, and BICS. There are other flag setting instructions, notably CMP, CMN and TST, but these do not take an S suffix.

The operations ADC and SBC perform additions and subtractions that also use the carry condition flag as an input.

  ADC{S}: Rd = Rn + Rm + C
  SBC{S}: Rd = Rn - Rm - 1 + C

Example 6.1. Arithmetic instructions

  ADD W0, W1, W2, LSL #3                 // W0 = W1 + (W2 << 3)
  SUBS X0, X4, X3, ASR #2                // X0 = X4 - (X3 >> 2), set flags
  MOV X0, X1                             // Copy X1 to X0
  CMP W3, W4                             // Set flags based on W3 - W4
  ADD W0, W5, #27                        // W0 = W5 + 27

The logical operations are essentially the same as the corresponding boolean operators operating on individual bits of the register.

The BIC (Bitwise bit Clear) instruction performs an AND of the register that is the first after the destination register, with the inverted value of the second operand. For example, to clear bit [11] of register X0, use:

  MOV X1, #0x800
  BIC X0, X0, X1

ORN and EON perform an OR or EOR respectively with a bitwise-NOT of the second operand.

The comparison instructions only modify the flags and have no other effect. The range of immediate values for these instructions is 12 bits, and this value can be optionally shifted 12 bits to the left.

Copyright © 2015 ARM. All rights reserved.ARM DEN0024A