ISA & Assembly
In RISC-V instructions, each register field (rd, rs1, rs2) is 5 bits wide. Why?
- ABecause the registers are 5 bits wide
- BBecause one instruction can use up to five registers
- CThere are 32 integer registers, and 2^5 = 32 values can name each of them
Show answer and explanation
Answer: C. There are 32 integer registers, and 2^5 = 32 values can name each of them
An R-type instruction consists, from the top, of funct7 (7 bits), rs2 (5), rs1 (5), funct3 (3), rd (5) and opcode (7), 32 bits in total. With 32 registers, a register number fits in 5 bits. Going to 64 registers would need 6 bits per field, 3 extra bits for three fields, leaving fewer bits for immediates and opcodes. The number of registers is tied to the instruction format.
- A. Registers are 32 or 64 bits wide.
- B. Base instructions use at most three registers: rd, rs1 and rs2.
- C. Correct. Five bits encode 0 to 31.