Instruction Reference¶
These tables provide summaries for the baseline RISC-V instructions and common extensions. Full specifications be found on the RISC-V website. Additionally, more details about each instruction can be found here.
Pseudo Instructions¶
These pseudo-instructions represent additional actions and can be used like regular instructions. One of the early passes in the assembler will transform them as described in this table.
Instruction |
Expansion |
Description |
---|---|---|
|
|
No operation |
|
See below |
Load immediate |
|
|
Copy register |
|
|
One’s complement |
|
|
Two’s complement |
|
|
Set if == zero |
|
|
Set if != zero |
|
|
Set if < zero |
|
|
Set if > zero |
|
|
Branch if == zero |
|
|
Branch if != zero |
|
|
Branch if <= zero |
|
|
Branch if >= zero |
|
|
Branch if < zero |
|
|
Branch if > zero |
|
|
Branch if > |
|
|
Branch if <= |
|
|
Branch if > (unsigned) |
|
|
Branch if <= (unsigned) |
|
|
Jump |
|
|
Jump and link |
|
|
Jump register |
|
|
Jump and link register |
|
|
Return from subroutine |
|
See below |
Call far-away subroutine |
|
See below |
Tail call far-away subroutine |
|
|
Fence on all memory and I/O |
Expansion of li rd, imm
¶
Depending on the value of the imm
, li
may get expanded into a few different combinations of instructions.
Criteria |
Expansion |
---|---|
|
|
|
|
otherwise |
lui rd, %hi(imm) addi rd, rd, %lo(imm) |
Expansion of call offset
¶
Depending on how near / far away the label referred to by offset
is, call
may get expanded into a few different combinations of instructions.
Criteria |
Expansion |
---|---|
|
|
otherwise |
auipc x1, %hi(offset) jalr x1, x1, %lo(offset) |
Expansion of tail offset
¶
Depending on how near / far away the label referred to by offset
is, tail
may get expanded into a few different combinations of instructions.
Criteria |
Expansion |
---|---|
|
|
otherwise |
auipc x6, %hi(offset) jalr x0, x6, %lo(offset) |
RV32I Base Instruction Set¶
Instruction |
Description |
---|---|
|
load upper 20 bits of |
|
load upper 20 bits of |
|
jump offset 20-bit MO2 |
|
jump offset 12-bit MO2 |
|
jump offset 12-bit MO2 |
|
jump offset 12-bit MO2 |
|
jump offset 12-bit MO2 |
|
jump offset 12-bit MO2 |
|
jump offset 12-bit MO2 |
|
jump offset 12-bit MO2 |
|
load 8-bit value from addr in |
|
load 16-bit value from addr in |
|
load 32-bit value from addr in |
|
load 8-bit value from addr in |
|
load 16-bit value from addr in |
|
store 8-bit value from |
|
store 16-bit value from |
|
store 32-bit value from |
|
add 12-bit |
|
store 1 into |
|
store 1 into |
|
bitwise XOR 12-bit |
|
bitwise OR 12-bit |
|
bitwise AND 12-bit |
|
shift |
|
shift |
|
shift |
|
add |
|
subtract |
|
shift |
|
store 1 into |
|
store 1 into |
|
bitwise XOR |
|
shift |
|
shift |
|
bitwise OR |
|
bitwise AND |
|
order device I/O and memory accesses |
|
make a service request to the execution environment |
|
return control to a debugging environment |
RV32M Standard Extension¶
Instruction |
Description |
---|---|
|
multiply |
|
multiply |
|
multiply |
|
multiply |
|
divide (signed) |
|
divide (unsigned) |
|
remainder (signed) of |
|
remainder (unsigned) of |
RV32A Standard Extension¶
All of the following atomic instructions also accept two additional parameters: aq
and rl
.
These are short for “acquire” and “release” and must either be both specified or both unspecified.
The default for each if unspecified is zero.
For example:
# both aq and rl are zero
lr.w t0 t1
lr.w t0 t1 0 0
# both aq and rl are one
lr.w t0 t1 1 1
# mix and match
lr.w t0 t1 0 1 # aq=0, rl=1
lr.w t0 t1 1 0 # aq=1, rl=0
Instruction |
Description |
---|---|
|
load (reserved) 32-bit value from addr in |
|
store (conditional) 32-bit value from |
|
atomically load value from addr in |
|
atomically load value from addr in |
|
atomically load value from addr in |
|
atomically load value from addr in |
|
atomically load value from addr in |
|
atomically load value from addr in |
|
atomically load value from addr in |
|
atomically load value from addr in |
|
atomically load value from addr in |
RV32C Standard Extension¶
Instruction |
Description |
---|---|
|
add 8-bit MO4 |
|
load 32-bit value from addr in |
|
store 32-bit value from |
|
no operation |
|
add 6-bit |
|
jump offset 11-bit MO2 |
|
load 6-bit |
|
add 6-bit MO16 |
|
load 6-bit |
|
shift |
|
shift |
|
bitwise AND 6-bit |
|
subtract |
|
bitwise XOR |
|
bitwise OR |
|
bitwise AND |
|
jump offset 11-bit MO2 |
|
jump offset 8-bit MO2 |
|
jump offset 8-bit MO2 |
|
shift |
|
load 32-bit value from addr in |
|
jump to addr in |
|
copy value from |
|
return control to a debugging environment |
|
jump to addr in |
|
add |
|
store 32-bit value from |
“Zifencei” Standard Extension¶
Instruction |
Description |
---|---|
|
synchronize the instruction and data streams |
“Zicsr” Standard Extension¶
Instruction |
Description |
---|---|
|
atomically swap values in CSRs |
|
atomically read and set bits in CSRs |
|
atomically read and clear bits in CSRs |
|
atomically swap values in CSRs (immediate) |
|
atomically read and set bits in CSRs (immediate) |
|
atomically read and clear bits in CSRs (immediate) |