| |||
| 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.
See also Parallel add and subtract.
op{S}{cond} {Rd},Rn,Operand2op{cond} {Rd},Rn, #imm12; Thumb-2 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
(see Conditional execution).
condis an optional condition code (see Conditional execution).
Rdis the destination register.
Rnis the register holding the first operand.
Operand2is a flexible second operand. See Flexible second operand for details of the option.
imm12is any value in the range 0-4095. Only permitted
for ADD and SUB instructions, and only
in Thumb-2 code.
The ADD instruction adds the values in and Rn.Operand2
The SUB instruction subtracts the value of from
the value in Operand2.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 (see Multiword arithmetic examples).
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. See Instruction substitution for details.
In most of these instructions, you cannot use r15 for ,
or any operand.Rd
The exception is that you can use r15 for in 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.
See also SUBS pc, LR.
See also ADR.
If you use r15 as ,
the value used is the address of the instruction plus 8.Rn
If you use r15 as :Rd
Execution branches to the address corresponding to the result.
If you use the S suffix,
the SPSR of the current mode is copied to the CPSR. You can use
this to return from exceptions (see Chapter 6 Handling
Processor Exceptions in the RealView Compilation Tools Developer Guide).
See also ADR.
Do not use the S suffix when using
r15 as in User
mode or System mode. The effect of such an instruction is unpredictable,
but the assembler cannot warn you at assembly time.Rd
You cannot use r15 for or
any operand in any data processing instruction that has a register-controlled
shift (see Flexible second operand).Rd
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 when used in Thumb-2 code:
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