RV32 Reference Card IAC2024
RV32 Reference Card IAC2024
RV32 Reference Card IAC2024
Instruction Formats
31 27 26 25 24 20 19 15 14 12 11 7 6 0
R-Type funct7 rb ra funct3 rd opcode
I-Type imm[11:0] ra funct3 rd opcode
S-Type imm[11:5] rb ra funct3 imm[4:0] opcode
B-Type imm[ 12 | 10:5 ] rb ra funct3 imm[ 4:1 | 11 ] opcode
U-Type imm[31:12] rd opcode
J-Type imm[ 20 | 10:1 | 11 | 19:12 ] rd opcode
R3-Type funct5 fmt rb ra funct3 rd opcode
R4-Type rc fmt rb ra funct3 rd opcode
Note: on B-Type and J-Type instructions the encoding omits bit 0 of the immediate field.
RV32IM Instructions
Encoding
Instruction Name RTL Description
Type Opcode funct3 funct7
- nop No Operation Pseudo-inst.: addi x0,x0,0 -
li xd,imm Load (move) Immediate Pseudo-inst.: Myriad sequence xd imm
la xd,symbol Load Address Pseudo-inst.: auipc + addi xd imm (symbol)
Move
mulsu xd,xa,xb Multiply High (S⇥U) R 0110011 0x2 0x01 xd (xa ⇥ xb)[63:32]
mulu xd,xa,xb Multiply High (U⇥U) R 0110011 0x3 0x01 xd (xa ⇥ xb)[63:32]
div xd,xa,xb Divide R 0110011 0x4 0x01 xd xa / xb
divu xd,xa,xb Divide (U) R 0110011 0x5 0x01 xd xa / xb
rem xd,xa,xb Remainder R 0110011 0x6 0x01 xd xa % xb
remu xd,xa,xb Remainder (U) R 0110011 0x7 0x01 xd xa % xb
l{b|h|w} xd,symbol Load From Global Symbol Pseudo-inst.: auipc + l{b|h|w} xd M[symbol] (B/H/W)
lb xd,imm(xa) Load Byte I 0000011 0x0 xd M[xa+imm] (B)
lh xd,imm(xa) Load Halfword I 0000011 0x1 xd M[xa+imm] (H)
Load Word I
Load, Store
sltiu xd,xa,imm Set Less Than Imm (U) I 0010011 0x3 xd (xa < imm)?1:0
seqz xd,xs Set Equal Zero Pseudo-inst.: sltiu xd, xs, 1 xd (xs == 0)?1:0
snez xd,xs Set Not Equal Zero Pseudo-inst.: sltu xd, x0, xs xd (xs != 0)?1:0
sltz xd,xs Set Less Than Zero Pseudo-inst.: slt xd, xs, x0 xd (xs < 0)?1:0
sgtz xd,xs Set Greater Than Zero Pseudo-inst.: slt xd, x0, xs xd (xs > 0)?1:0
beq xa,xb,imm Branch Equal B 1100011 0x0 if(xa==xb) PC PC + imm
bne xa,xb,imm Branch Not Equal B 1100011 0x1 if(xa!=xb) PC PC + imm
bgt xs, xt, offset Branch Greater Than Pseudo-inst.: blt xt, xs, offset if (xs> xt) PC symbol
bge xa,xb,imm Branch Greater or Equal B 1100011 0x5 if(xa>=xb) PC PC + imm
ble xs, xt, offset Branch Less or Equal Pseudo-inst.: bge xt, xs, offset if (xs<=xt) PC symbol
blt xa,xb,imm Branch Less Than B 1100011 0x4 if(xa< xb) PC PC + imm
Flow control (branch, jump, call, ret)
bgtu xs, xt, offset Branch Less Than (U) Pseudo-inst.: bltu xt, xs, offset if (xs> xt) PC symbol
bgeu xa,xb,imm Branch Greater or Equal (U) B 1100011 0x7 if(xa>=xb) PC PC + imm
bleu xs, xt, offset Branch Less or Equal (U) Pseudo-inst.: bgeu xt, xs, offset if (xs<=xt) PC symbol
bltu xa,xb,imm Branch Less Than (U) B 1100011 0x6 if(xa< xb) PC PC + imm
beqz xs, symbol Branch Equal Zero Pseudo-inst.: beq xs, x0, offset if (xs==0) PC symbol
bnez xs, symbol Branch Not Equal Zero Pseudo-inst.: bne xs, x0, offset if (xs!=0) PC symbol
blez xs, symbol Branch Less or Equal Zero Pseudo-inst.: bge x0, xs, offset if (xs<=0) PC symbol
bgez xs, symbol Branch Greater or Equal Zero Pseudo-inst.: bge xs, x0, offset if (xs>=0) PC symbol
bltz xs, symbol Branch Less Than Zero Pseudo-inst.: blt xs, x0, offset if (xs< 0) PC symbol
bgtz xs, symbol Branch Greater Than Zero Pseudo-inst.: blt x0, xs, offset if (xs> 0) PC symbol
j symbol Jump Pseudo-inst.: jal x0, offset PC symbol
jal xd,imm Jump And Link J 1101111 xd PC+4; PC PC + imm
jal symbol Jump And Link To Symbol Pseudo-inst.: jal x1, offset x1 PC + 4; PC symbol
jr xs Jump Register Pseudo-inst.: jalr x0, xs, 0 PC xs
jalr xs Jump And Link Register Pseudo-inst.: jalr x1, xs, 0 x1 PC + 4; PC xs
jalr xd,xa,imm Jump And Link Register I 1100111 0x0 xd PC+4; PC xa + imm
call symbol Call subroutine Pseudo-inst.: auipc + jalr x1 PC + 4; PC symbol
ret Return from subroutine Pseudo-inst.: jalr x0, x1, 0 PC x1
ecall Environment Call I 1110011 imm=0x0, others=0 SEPC PC + 4; PC STVEC
Environment Break I
OS
flt.{s|d} xd,fa,fb FP Less Than R3 1010011 001 {0x50|0x51} xd = (fa < fb) ? 1 : 0
fle.{s|d} xd,fa,fb FP Less or Equal R3 1010011 000 {0x50|0x51} xd = (fa <= fb) ? 1 : 0
fclass.{s|d} xd,fa FP Classify R3 1010011 001 {0x70|0x71} xd = (fa type?):0..9
⇤ – To encode fcvt.{s|d}.w and fcvt.w.{s|d} set xb=0; for fcvt.{s|d}.w and fcvt.w.{s|d} set xb=1.
rm – Floating point rounding mode. Set to "000" to select round to nearest.
Observation: Designations fl{w|d} and fs{w|d} represent the corresponding instructions for SP FP load/store (flw/fsw) and for DP FP
load/store (fld/fsd). Similarly, designations f__.{s|d} are used to represent the corresponding SP (f__.s) and DP (f__.d) instructions.