AMOADD.B

RISC-V AMOADD.B Instruction Details

Instruction ManualAMO-type

Atomic byte add: rd = *rs1 (sign-ext), *rs1 += rs2[7:0]

Instruction Syntax

amoadd.b rd, rs2, (rs1)
Operand Breakdown
rd: receives the old memory value read atomically; for AMOCAS, its pre-execution value also supplies the compare value.
rs1: directly supplies the atomic-memory address; AMO assembly syntax has no offset immediate field.
rs2: supplies the AMO source data; for AMOCAS, it is the swap value stored when the comparison matches.
AMO-type is this site's presentation label for the AMO-specific R-type field layout: funct5, aq, rl, rs2, rs1, funct3, rd, and the AMO opcode encode the operation.
ZabhaAtomic

Instruction Behavior

AMOADD.B is a Zabha instruction that depends on Zaamo. It atomically loads a byte from the address in rs1 into rd (sign-extended), adds the low byte of rs2 (overflow wraps), and stores the result back. It supports aq/rl bits.

AMOADD.B Atomic Decode And Execute Animation

Shows Zabha (requires Zaamo) byte atomic field decode, aq/rl ordering bits, a memory read, and RMW state update.

rd
rs2
rs1
amoadd.b
,
,(
)
Execution Context
31..27
26
25
24..20
19..15
14..12
11..7
6..0
00000
funct5
0
aq
0
rl
01011
rs2
01010
rs1
000
funct3
00101
rd
0101111
opcode
Atomic Data Path
instruction
0x00B502AF
opcode
0101111 -> AMO
funct3
000 -> byte width
funct5
00000 -> AMOADD.B
aq / rl
0/0 -> unordered
rd / rs2 / rs1
t0(x5) / a1(x11)=0x20 / a0(x10)=0x00001000
memory read
mem[0x00001000] -> old byte 0xF2
RMW
0xF2 + 0x20 -> 0x12
rd / memory
t0(x5) = 0xFFFFFFF2; mem[0x00001000] = 0x12
Current Step

Concept Step: receive the 32-bit atomic instruction encoding

Zabha depends on Zaamo; Zabha-extension byte atomic instructions use a 32-bit encoding; the animation starts by splitting the fields.

encoding: 0x00B502AF
syntax : amoadd.b t0(x5), a1(x11), (a0(x10))
result : t0(x5) = 0xFFFFFFF2; mem[0x00001000] = 0x12
8-bit Byte Addition
old byte
0xF2
rs2 byte
0x20
low 8-bit sum
0xF2 + 0x20
memory result
0x12

AMOADD.B uses full 8-bit byte addition and writes the low 8-bit result to memory; this view avoids per-bit equations that would hide the carry chain.

This animation shows ISA-visible atomic read-modify-write, compare-and-swap, LR/SC reservation state, and ordering bits, not any specific CPU cache-coherence implementation, pipeline, or timing.

Quick Understanding & Search Notes

AMOADD.B is a Zabha 8-bit atomic add instruction. It atomically reads the old memory value, performs the read-modify-write at 8-bit width, and writes the sign-extended old value to rd.

Only the 8-bit subword is operated on; upper bits of rs2 are ignored.
rd receives the old memory value sign-extended to XLEN, not the newly updated value.
The natural-alignment requirement for a byte operand is one byte, so every byte address is naturally aligned. aq/rl affects ordering, not the data result.

Common Usage Scenarios

Atomic & Sync

Understand this scenario with real code like «amoadd.b a0, a2, (a1)».

Network & Byte Order

Understand this scenario with real code like «amoadd.b a0, a2, (a1)».

Pre-Use Checklist

Syntax Check
  • Confirm the current instruction format is AMO-type.
  • Confirm the operand order matches the example.
Semantic Check
  • Ensure the destination register usage is compatible with the calling convention.
  • Confirm this is not the lower-level form of a pseudo-instruction expansion.

Pitfalls / Common Confusions

rd returns old memory value (sign-extended to XLEN), not the operation result
Addition overflow wraps (modulo 256); byte overflow does not affect higher bytes
The natural-alignment requirement for a byte operand is one byte, so every byte address is naturally aligned.

FAQ

Does AMOADD.B return the post-operation value?

No. Like A-extension AMOs, rd receives the old value loaded from memory.

Can AMOADD.B affect neighboring bytes?

Architecturally it modifies only the byte operand; Zabha provides native byte-granule atomic read-modify-write operations.