11.10 ADD

Add without Carry.

Syntax

ADD{S}{cond} {Rd}, Rn, Operand2

ADD{cond} {Rd}, Rn, #imm12 ; Thumb, 32-bit encoding only

where:

S

is an optional suffix. If S is specified, the condition flags are updated on the result of the operation.

cond

is an optional condition code.

Rd

is the destination register.

Rn

is the register holding the first operand.

Operand2

is a flexible second operand.

imm12

is any value in the range 0-4095.

Operation

The ADD instruction adds the values in Rn and Operand2 or imm12.

In certain circumstances, the assembler can substitute one instruction for another. Be aware of this when reading disassembly listings.

Use of PC and SP in Thumb instructions

Generally, you cannot use PC (R15) for Rd, or any operand.

The exceptions are:

  • you can use PC for Rn in 32-bit encodings of Thumb ADD instructions, with a constant Operand2 value in the range 0-4095, and no S suffix. These instructions are useful for generating PC-relative addresses. Bit[1] of the PC value reads as 0 in this case, so that the base address for the calculation is always word-aligned.

  • you can use PC in 16-bit encodings of Thumb ADD{cond} Rd, Rd, Rm instructions, where both registers cannot be PC. However, the following 16-bit Thumb instructions are deprecated in ARMv6T2 and above:

    • ADD{cond} PC, SP, PC.

    • ADD{cond} SP, SP, PC.

Generally, you cannot use SP (R13) for Rd, or any operand. Except that:

  • You can use SP for Rn in ADD instructions.

  • ADD{cond} SP, SP, SP is permitted but is deprecated in ARMv6T2 and above.

  • ADD{S}{cond} SP, SP, Rm{,shift} and SUB{S}{cond} SP, SP, Rm{,shift} are permitted if shift is omitted or LSL #1, LSL #2, or LSL #3.

Use of PC and SP in ARM instructions

You cannot use PC for Rd or any operand in any data processing instruction that has a register-controlled shift.

In ADD instructions without register-controlled shift, use of PC is deprecated except for the following cases:

  • Use of PC for Rd in instructions that do not add SP to a register.

  • Use of PC for Rn and use of PC for Rm in instructions that add two registers other than SP.

  • Use of PC for Rn in the instruction ADD{cond} Rd, Rn, #Constant.

If you use PC (R15) as Rn or Rm, the value used is the address of the instruction plus 8.

If you use PC as Rd:

  • Execution branches to the address corresponding to the result.

  • If you use the S suffix, see the SUBS pc,lr instruction.

You can use SP for Rn in ADD instructions, however, ADDS PC, SP, #Constant is deprecated.

You can use SP in ADD (register) if Rn is SP and shift is omitted or LSL #1, LSL #2, or LSL #3.

Other uses of SP in these ARM instructions are deprecated.

Note:

The deprecation of SP and PC in ARM instructions is only in ARMv6T2 and above.

Condition flags

If S is specified, these instructions update the N, Z, C and V flags according to the result.

16-bit instructions

The following forms of these instructions are available in Thumb code, and are 16-bit instructions:

ADDS Rd, Rn, #imm

imm range 0-7. Rd and Rn must both be Lo registers. This form can only be used outside an IT block.

ADD{cond} Rd, Rn, #imm

imm range 0-7. Rd and Rn must both be Lo registers. This form can only be used inside an IT block.

ADDS Rd, Rn, Rm

Rd, Rn and Rm must all be Lo registers. This form can only be used outside an IT block.

ADD{cond} Rd, Rn, Rm

Rd, Rn and Rm must all be Lo registers. This form can only be used inside an IT block.

ADD Rd, Rd, Rm

ARMv6 and earlier: either Rd or Rm, or both, must be a Hi register. ARMv6T2 and above: this restriction does not apply.

ADDS Rd, Rd, #imm

imm range 0-255. Rd must be a Lo register. This form can only be used outside an IT block.

ADD{cond} Rd, Rd, #imm

imm range 0-255. Rd must be a Lo register. This form can only be used inside an IT block.

ADD SP, SP, #imm

imm range 0-508, word aligned.

ADD Rd, SP, #imm

imm range 0-1020, word aligned. Rd must be a Lo register.

ADD Rd, pc, #imm

imm range 0-1020, word aligned. Rd must be a Lo register. Bits[1:0] of the PC are read as 0 in this instruction.

Example

    ADD     r2, r1, r3

Multiword arithmetic example

These two instructions add a 64-bit integer contained in R2 and R3 to another 64-bit integer contained in R0 and R1, and place the result in R4 and R5.

    ADDS    r4, r0, r2    ; adding the least significant words
    ADC     r5, r1, r3    ; adding the most significant words
Non-ConfidentialPDF file icon PDF versionARM DUI0473M
Copyright © 2010-2016 ARM Limited or its affiliates. All rights reserved.