The R-type (register-type) instruction in RISC-V operates on three registers. Two of these registers serve as source registers rs2 and rs1, providing the input operands, while the third register rd functions as the destination register, storing the result of the operation. This format is commonly used for arithmetic and logical operations in the instruction set. Figure 1, illustrates the instruction format of the R-type instruction.

Figure 1: Instruction Format

Figure 1: Instruction Format

The R-Type instruction in RISC-V is a 32-bit instruction that contains essential information to execute arithmetic or logical operations. These 32 bits are divided into six different fields:

  • Opcode: The opcode or operation code is a 7-bit field that defines the type of operation to be performed on the data stored in the source registers.
  • Destination Register: Stores the result of the operation in the destination register rd.
  • Function Fields: Together, these funct7 7-bit and 3-bit funct3 fields, known as control bits, determine the specific operation to be executed.
  • Source Registers: Each, rs1 and rs2, 5-bit field holds the address of the input operands.

The table below provides a detailed breakdown of all R-Type instructions in RISC-V, along with their encoded information. For simplicity, the source (rs1, rs2) and destination (rd) registers are not included in the table but are used for describing the operations.

funct7funct3opcodeDescriptionInstruction
00000000000110011 (51)addadd rd, rs1, rs2
00000000010110011 (51)shift left logicalsll rd, rs1, rs2
00000000100110011 (51)set less thanslt rd, rs1, rs2
00000000110110011 (51)set less than unsignedsltu rd, rs1, rs2
00000001000110011 (51)xorxor rd, rs1, rs2
00000001010110011 (51)shift right logicalsrl rd, rs1, rs2
00000001100110011 (51)oror rd, rs1, rs2
00000001110110011 (51)andadd rd, rs1, rs2
01000000000110011 (51)subsub rd, rs1, rs2
01000001010110011 (51)shift right arithmeticsra rd, rs1, rs2