adds

Add and Set Flags (Immediate 64-bit)

ADDS <Xd>, <Xn|SP>, #<imm> {, lsl #<shift>}

Adds immediate and updates flags (64-bit).

Details

Add immediate value to 64-bit register and set condition flags. Adds a 12-bit immediate (optionally left-shifted by 0 or 12 bits) to Xn, stores the result in Xd, and updates the N, Z, C, and V flags based on the result. AArch64-only instruction executing at any privilege level.

Pseudocode Operation

imm_val ← imm12 << (sh * 12)
result ← Xn + imm_val
Xd ← result
N ← result[63]
Z ← (result == 0)
C ← CarryOut(Xn, imm_val)
V ← OverflowFrom(Xn, imm_val)

Example

ADDS x0, x1, #16

Encoding

Binary Layout
1
0
1
100010
sh
imm12
Rn
Rd
 
Format Data Processing (Immediate)
Opcode 0xB1000000
Extension Base

Operands

  • Xd
    Destination 64-bit integer register
  • Xn
    First source / base 64-bit integer register
  • imm
    Imm

Reference (Arm A64 ISA)

Instruction Forms

Encoding Instruction ISA Bit pattern
0x2B200000 ADDS <Wd>, <Wn|WSP>, <Wm>{, <extend> {#<amount>}} A64 0 | 0 | 1 | 01011 | 00 | 1 | Rm | option | imm3 | Rn | Rd
0xAB200000 ADDS <Xd>, <Xn|SP>, <R><m>{, <extend> {#<amount>}} A64 1 | 0 | 1 | 01011 | 00 | 1 | Rm | option | imm3 | Rn | Rd
0x31000000 ADDS <Wd>, <Wn|WSP>, #<imm>{, <shift>} A64 0 | 0 | 1 | 100010 | sh | imm12 | Rn | Rd
0xB1000000 ADDS <Xd>, <Xn|SP>, #<imm>{, <shift>} A64 1 | 0 | 1 | 100010 | sh | imm12 | Rn | Rd
0x2B000000 ADDS <Wd>, <Wn>, <Wm>{, <shift> #<amount>} A64 0 | 0 | 1 | 01011 | shift | 0 | Rm | imm6 | Rn | Rd
0xAB000000 ADDS <Xd>, <Xn>, <Xm>{, <shift> #<amount>} A64 1 | 0 | 1 | 01011 | shift | 0 | Rm | imm6 | Rn | Rd

Description

Add (immediate), setting flags, adds a register value and an optionally-shifted immediate value, and writes the result to the destination register. It updates the condition flags based on the result.

Operation

bits(datasize) result;
bits(datasize) operand1 = if n == 31 then SP[]<datasize-1:0> else X[n, datasize];
bits(4) nzcv;


(result, nzcv) = AddWithCarry(operand1, imm, '0');

PSTATE.<N,Z,C,V> = nzcv;

X[d, datasize] = result;