Types of operations:
- Integer register-register operations (R-type)
- Integer register-immediate operations (I-type/U-type)
- No-operation (NOP)
Int Register-Register
Executes an operation on data from two registers (source) and stores it in a new register (destination) from the register file (RF)
RF[rd] = f(RF[rs1], RF[rs2])
It is formatted over 32 bits as such:
| funct7 | rs2 | rs1 | funct3 | rd | opcode |
|---|---|---|---|---|---|
| 7 | 5 | 5 | 3 | 5 | 7 |
| 7bit function code | source index | source index | 3 bit function code | destination index | 7bit operation code OP |
Example
For xor of t1 and t2 and stored into t0:
0000000 - funct700111 - rs200110 - rs1100 - funct300101 - rd0110011 - opcodeWhich gives:
0x007342B3as the 32bit operation
We have the operations:
- ADD/SUB — addition/subtraction
- AND/OR/XOR — bitwise logical operations
- SLL/SRL/SRA — logical left/right/arithmetic shift
- SLT/SLTU — (un)signed comparisons
Example
Let’s do in risc-v:
# add b and c into a add t0, t1, t2 # add d to b + c into a add t0, t0, s0 # subtract e to a into a sub t0, t0, s1
Int Register-Immediate
Immediate ⇐> integer literal
Can be signed or unsigned
I type
I-type
Is in the format (Except for shifting):
| imm | rs1 | funct3 | rd | opcode |
|---|---|---|---|---|
| 12 | 5 | 3 | 5 | 7 |
| 12-bit immediate | source index | 3bit function | destination index | operation code OP-IMM |
For shifting we have:
| funct7 | imm | rs1 | funct3 | rd | opcode |
|---|---|---|---|---|---|
| 7 | 5 | 5 | 3 | 5 | 7 |
| 7 bit function | 5-bit immediate | source index | 3 bit function | destination index | operation code OP-IMM |
U type
U-type — Upper Immediate
Is in the format:
| imm | rd | opcode |
|---|---|---|
| 20 | 5 | 7 |
| 20-bit immediate | destination index | operation code |
With those two types of immediate operations, we can load a full 32bit number
NOP
“No operation”
Just advances program counter
It is the equivalent of addi x0, x0, 0