li
Load immediate
Loads an immediate constant into a register, using as many instructions as the value needs.
Used in
- Loads, stores and immediatesRISC-V assembly
- Asking a question with a branchRISC-V assembly
- .data, .text and directivesRISC-V assembly
- Going 64-bitRISC-V assembly
- if, else and jump tablesRISC-V assembly
- LoopsRISC-V assembly
- Arithmetic, logic and bitsRISC-V assembly
- Arrays and stringsRISC-V assembly
- The stack and spRISC-V assembly
- jal, ret and the calling conventionRISC-V assembly
Forms
Operands
t1- Any integer register,
x0tox31, or its named alias, such aszero,t0ort6. imm- An immediate value: a signed 12-bit value (
-2048to2047), a 32-bit value (-2147483648to4294967295) or a 64-bit value in RV64 (signed decimal or a hexadecimal bit pattern up to0xFFFFFFFFFFFFFFFF). The size your value needs decides which real instructions the assembler uses. Open the row to see them for each size.
This example runs on RV64.
# li writes 123 to t0.
.data
marker: .word 17
.text
li t0, 123