4 ms·
It's absolutely normal with RISC ISAs that use 4 byte instructions. There is plenty of room to specify three 5-bit register numbers, and it often prevents needi
by brucehoult 6y ago
It's absolutely normal with RISC ISAs that use 4 byte instructions. There is plenty of room to specify three 5-bit register numbers, and it often prevents needing extra MOV instructions.
RISC-V also has instructions that are two bytes long. The assembler automatically uses a 2 byte instruction instead of the corresponding four byte instruction if it can.
Examples of available two byte instructions:
Using any of the 32 registers:
- move or add one register to another
- shift left by a constant 0..63
- add a constant -32..+31 to a register
- load or store a register within 0..63 register sizes above the stack pointer
Using only the eight "most popular" registers (s0..s1, a0..a5):
- subtract, AND, OR, XOR two registers
- AND with a constant -32..+31
- logical or arithmetic shift right by a constant 1..63
- load or store a 32 or 64 bit value at an offset of 0..31 operand widths above the address in a register.
The programmer (or even compiler) doesn't need to remember which operations and registers are supported by 2 byte instructions, the assembler just selects them automatically when possible.
Of course you can decrease your code size if you do know what can use a 2 byte instruction and organise your code to maximise it.