ben's notes

RISC-V Quick Reference

opcodes #

  • R: 0110011
  • I: 0010011
  • S: 0100011
  • B: 1100011

registers #

Registers

Example instruction

j vs jr vs jal vs jalr #

j label is a pseudoinstruction for jal x0, label

ret = jr ra = jalr x0, ra, 0

jal ra, label calls function within $2^{18}$ instructions of PC

  • is a J instruction
  • saves PC + 4 in register ra
  • Sets PC to PC + offset

jalr rd, rs, immediate:

  • is an I instruction
  • saves PC + 4 in register rd
  • sets PC to rs + immediate (doesn’t use PC itself in calculation)
  • Absolute use: lui x1, <hi20bits> then jalr ra, x1, <lo12bits>
  • Relative use: auipc x1, <hi20bits> then jalr x0, x1, <lo12bits>

Psuedoinstructions #

Memory allocation #