| |||
| Home > ARM and Thumb Instructions > General data processing instructions > ADD, SUB, RSB, ADC, SBC, and RSC | |||
Add, Subtract, and Reverse Subtract, each with or without Carry.
op{S}{cond} {Rd},Rn,Operand2
op{cond} {Rd},Rn, #imm12; Thumb-2 ADD and SUB only
where:
opis one of:
ADDAdd.
ADCAdd with Carry.
SUBSubtract.
RSBReverse Subtract.
SBCSubtract with Carry.
RSCReverse Subtract with Carry (ARM only).
Sis
an optional suffix. If S is specified, the
condition code flags are updated on the result of the operation.
condis an optional condition code.
Rdis the destination register.
Rnis the register holding the first operand.
Operand2is a flexible second operand.
imm12is any value in the range 0-4095.
The ADD instruction adds the values in and Rn or Operand2imm12.
The SUB instruction subtracts the value of or Operand2 from
the value in imm12.Rn
The RSB (Reverse Subtract) instruction subtracts
the value in from
the value of Rn.
This is useful because of the wide range of options for Operand2.Operand2
You can use ADC, SBC, and RSC to
synthesize multiword arithmetic.
The ADC (Add with Carry) instruction adds the
values in and Rn,
together with the carry flag.Operand2
The SBC (Subtract with Carry) instruction subtracts
the value of from
the value in Operand2.
If the carry flag is clear, the result is reduced by one.Rn
The RSC (Reverse Subtract with Carry) instruction
subtracts the value in from
the value of Rn.
If the carry flag is clear, the result is reduced by one.Operand2
In certain circumstances, the assembler can substitute one instruction for another. Be aware of this when reading disassembly listings.
In most of these instructions, you cannot use PC (R15)
for , or any operand.Rd
The exceptions are:
you can use
PC for in 32-bit
Thumb RnADD and SUB instructions, with a
constant value
in the range 0-4095, and no Operand2S 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 Thumb ADD{ instructions, where both registers cannot be PC.
However, the following 16-bit Thumb instructions are deprecated
in ARMv6T2 and above:cond}
Rd, Rd, Rm
ADD{cond}
PC, SP, PC
ADD{cond} SP, SP,
PC.
In most of these instructions, you cannot use SP (R13)
for , or any operand.
Except that:Rd
You can use SP for Rn in ADD and SUB instructions
ADD{ is permitted but is deprecated in ARMv6T2 and abovecond} SP, SP,
SP
ADD{S}{cond} SP, SP, Rm{, and shift}SUB{S}{cond}
SP, SP, Rm{, are permitted
if shift} is omitted
or shiftLSL #1, LSL #2, or LSL #3.
You cannot use PC for or
any operand in any data processing instruction that has a register-controlled
shift.Rd
With the exception of ADD and SUB,
use of PC for any operand, in instructions without register-controlled
shift, is deprecated.
In SUB instructions without register-controlled
shift, use of PC is deprecated except for the following cases:
Use of PC for R d
Use of PC for R in
the instruction nSUB{.cond} Rd,
Rn, #Constant
In ADD instructions without register-controlled
shift, use of PC is deprecated except for the following cases:
Use of PC for R in
instructions that do not add SP to a registerd
Use of PC for R and
use of PC for nR in
instructions that add two registers other than SPm
Use of PC for R in
the instruction nADD.{cond} Rd,
Rn, #Constant
If you use PC (R15) as or Rn,
the value used is the address of the instruction plus 8.Rm
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 in RnADD and
SUB instructions, however, ADDS PC, SP, #Constant and SUBS PC,
SP, #Constant are deprecated.
You can use SP in ADD (register) and SUB (register)
if is SP and Rn is
omitted or shiftLSL #1, LSL #2,
or LSL #3.
Other uses of SP in these ARM instructions are deprecated.
The deprecation of SP and PC in ARM instructions is only in ARMv6T2 and above.
If S is specified, these instructions
update the N, Z, C and V flags according to the result.
The following forms of these instructions are available in Thumb code, and are 16-bit instructions:
ADDS Rd, Rn,
#imm range
0-7. imm and Rd must
both be Lo registers.Rn
ADDS Rd, Rn, Rm, Rd and Rn must
all be Lo registers.Rm
ADD Rd, Rd, RmARMv6 and earlier: either or Rd,
or both, must be a Hi register. ARMv6T2 and above: this restriction
does not apply.Rm
ADDS Rd, Rd,
#imm range
0-255. imm must be
a Lo register.Rd
ADCS Rd, Rd, Rm, Rd and Rn must
all be Lo registers.Rm
ADD SP, SP, #imm range
0-508, word aligned.imm
ADD Rd,
SP, #imm range
0-1020, word aligned. imm must
be a Lo register.Rd
ADD Rd,
pc, #imm range
0-1020, word aligned. imm must
be a Lo register. Bits[1:0] of the PC are read as 0 in this instruction.Rd
SUBS Rd, Rn, Rm, Rd and Rn must
all be Lo registers.Rm
SUBS Rd, Rn,
#imm range
0-7. imm and Rd both
Lo registers.Rn
SUBS Rd, Rd,
#imm range
0-255. imm must be
a Lo register.Rd
SBCS Rd, Rd, Rm, Rd and Rn must
all be Lo registers.Rm
SUB SP, SP, #imm range
0-508, word aligned.imm
RSBS Rd, Rn,
#0 and Rd both
Lo registers.Rn
ADD r2, r1, r3
SUBS r8, r6, #240 ; sets the flags on the result
RSB r4, r4, #1280 ; subtracts contents of R4 from 1280
ADCHI r11, r0, r3 ; only executed if C flag set and Z
; flag clear
RSCSLE r0,r5,r0,LSL r4 ; conditional, flags set
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
These instructions subtract one 96-bit integer from another:
SUBS r3, r6, r9
SBCS r4, r7, r10
SBC r5, r8, r11
For clarity, the above examples use consecutive registers for multiword values. There is no requirement to do this. The following, for example, is perfectly valid:
SUBS r6, r6, r9
SBCS r9, r2, r1
SBC r2, r8, r11
Developing Software for ARM Processors: