addi
Add Immediate - 38 00 00 00
addi

Instruction Syntax

Mnemonic Format Description
addi rD,rA,SIMM Add immediate

Derived Forms

Mnemonic Format Description
li rD,value Load immediate (rA = 0)
la rD,disp(rA) Load address
subi rD,rA,value Subtract immediate (SIMM = -value)

Instruction Encoding

0
0
1
1
1
0
D
D
D
D
D
A
A
A
A
A
S
S
S
S
S
S
S
S
S
S
S
S
S
S
S
S

Field Bits Description
Primary Opcode 0-5 001110 (0x0E)
rD 6-10 Destination register
rA 11-15 Source register A (0 for li)
SIMM 16-31 16-bit signed immediate value

Operation

if rA = 0 then rD ← EXTS(SIMM)
else rD ← (rA) + EXTS(SIMM)

If rA is 0, the immediate value (sign-extended to 32 bits) is placed into rD. Otherwise, the sum of the contents of rA and the sign-extended immediate value is placed into rD.

Note: The addi instruction does not update the carry bit (XER[CA]) and has no overflow exception option.

Affected Registers

None - This instruction does not affect any condition register fields or XER register bits.

Examples

Basic Immediate Addition

addi r3, r1, 100   # r3 = r1 + 100
addi r5, r5, -50   # r5 = r5 - 50 (subtract 50)

Load Immediate (li)

li r3, 42          # r3 = 42 (equivalent to addi r3, 0, 42)
li r4, -1          # r4 = -1 (load -1 into r4)

Load Address (la)

la r3, 100(r1)     # r3 = r1 + 100 (load effective address)
la r4, data_offset(r2)  # r4 = r2 + data_offset

Subtract Immediate (subi)

subi r3, r1, 50    # r3 = r1 - 50 (equivalent to addi r3, r1, -50)

Common Usage Patterns

# Initialize register
li r0, 0           # Clear r0

# Adjust stack pointer
addi r1, r1, -16   # Allocate 16 bytes on stack
addi r1, r1, 16    # Deallocate 16 bytes from stack

# Array indexing
li r4, 0           # Initialize index
addi r4, r4, 4     # Move to next word (increment by 4)

Related Instructions

add, addic, addic., addis, subf, subfic

Back to Index