There are 21 computational instructions.
rd denotes a _d_estination _r_egister, rs1 and rs2 some _s_ource _r_egisters. imm stands for "immediate value".
|add rd, rs1, rs2||rd = rs1 + rs2|
|sub rd, rs1, rs2||rd = rs1 - rs2|
|sll rd, rs1, rs2||rd = rs1 << rs2||shift left logical by register|
|srl rd, rs1, rs2||TODO||shift right logical by register|
|sra rd, rs1, rs2||TODO||shift right arithm. by register|
|and rd, rs1, rs2||rd = rs1 & rs2||bitwise AND|
|or rd, rs1, rs2||rd = rs1 | rs2||bitwise OR|
|xor rd, rs1, rs2||rd = rs1 ^ rs2||bitwise XOR|
|slt rd, rs1, rs2||rd = ((int)rs1 < (int)rs2)||compare, set 1/0|
|sltu rd, rs1, rs2||rd = ((uint)rs1 < (uint)rs2)||compare, set 1/0|
|addi rd, rs1, imm||rd = rs1 + (int32_t)imm|
|slli rd, rs1, imm||rd = rs1 << imm[4:0]|
|srli rd, rs1, imm||???||shift right logical by immediate|
|srai rd, rs1, imm||???||shift right arithm. by immediate|
|andi rd, rs1, imm||rd = rs1 & imm||bitwise AND with immediate|
|ori rd, rs1, imm||rd = rs1 | imm||bitwise OR with immediate|
|xori rd, rs1, imm||rd = rs1 ^ imm||bitwise XOR with immediate|
|slti rd, rs1, imm||rd = ((int)rs1 < (int)imm)||sign-extend imm, compare, set 1/0|
|sltui rd, rs1, imm_||rd = ((uint)rs1 < (uint)imm)||sign-extend imm, compare as unsigned, set 1/0|
|lui rd, imm||rd = (imm << 12)||load upper immediate, set lower 12 bits to 0|
|auipc rd, imm||rd = pc + (imm << 12)||add upper immediate to |
Signed integers are stored as 2's complements. All of instructions sign-extend operands if needed.
- logical left shift by n: equivalent to multiplication by 2^n.
- logical right shift by n: equivalent to unsigned division by 2^n, rounding towards 0
- logical arithmetical shift by n: equivalent to unsigned division by 2^n, rounding down
- not rd, rs1 can be implemented as
xori rd, rs1, -1
- a pseudoinstruction seqz:
sltiu rd, rs1, 1, computes if rs1 is 0.
- a pseudoinstruction li rd, imm:
lui rd, imm[31:12]; addi rd, rd, imm[11:0]
- nop is usually defined as
addi x0, x0, 0
TODO: what happens on integer overflow?
auipc is a position-independent code shortcut, e.g.:
auipc x4, 0x1 lw x4, 0x234(x4)
allows to read a word from memory at
pc + 0x1234 into
pc at which point?
auipc are U-type.
Least significant byte looks like 37/B7, 17/97.
Instructions with rs2 are R-type:
Everything else is I-type.
93for instructions with immediates
B3for register instructions