wire / wire-format / riscv-instruction

RISC-V instruction encoding

RISC-V is an open ISA. Base 32-bit instructions are 4 bytes, aligned to 4 bytes. Six formats: R (register-register), I (immediate), S (store), B (branch), U (upper immediate), J (jump). All instructions have a 7-bit opcode (bits 0-6) and, for R/I/S/B, a 3-bit funct3 (bits 12-14). R-type also has 7-bit funct7 (bits 25-31).

wire-format kind wire-format status standard verification verified tier B wire-format@1

aka: RISC-V instruction encoding

wire format

spec: RISC-V specification (riscv.org)

RISC-V is an open ISA. Base 32-bit instructions are 4 bytes, aligned to 4 bytes. Six formats: R (register-register), I (immediate), S (store), B (branch), U (upper immediate), J (jump). All instructions have a 7-bit opcode (bits 0-6) and, for R/I/S/B, a 3-bit funct3 (bits 12-14). R-type also has 7-bit funct7 (bits 25-31).

fieldsizemeaning
R-type4 bytesfunct7[31:25] | rs2[24:20] | rs1[19:15] | funct3[14:12] | rd[11:7] | opcode[6:0]. E.g., ADD rd, rs1, rs2.
I-type4 bytesimm[31:20] | rs1[19:15] | funct3[14:12] | rd[11:7] | opcode[6:0]. E.g., ADDI rd, rs1, imm.
S-type4 bytesimm[31:25] | rs2[24:20] | rs1[19:15] | funct3[14:12] | imm[11:7] | opcode[6:0]. E.g., SW rs2, offset(rs1).
B-type4 bytesimm[12] | imm[10:5] | rs2[24:20] | rs1[19:15] | funct3[14:12] | imm[4:1] | imm[11] | opcode[6:0]. E.g., BEQ rs1, rs2, offset.
U-type4 bytesimm[31:12] | rd[11:7] | opcode[6:0]. E.g., LUI rd, imm.
J-type4 bytesimm[20] | imm[10:1] | imm[11] | imm[19:12] | rd[11:7] | opcode[6:0]. E.g., JAL rd, offset.
Compressed (RVC)2 bytes16-bit compressed instructions (C prefix) for code density. Quadrants 0-3 based on bits 1-0.
Registers32x0 (zero), x1 (ra), x2 (sp), x3 (gp), x4 (tp), x5-x7 (t0-t2), x8 (s0/fp), x9 (s1), x10-x17 (a0-a7), x18-x27 (s2-s11), x28-x31 (t3-t6). x0 is hardwired to 0.

example:

33 00 80 00

RISC-V: ADD x0, x1, x2 (R-type: funct7=0, rs2=2, rs1=1, funct3=0, rd=0, opcode=0x33)


provenance

agent: curl -H 'accept: application/json' wire.phall.io/wire-format/riscv-instruction or /wire-format/riscv-instruction.json