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:

funct7rs2rs1funct3rdopcode
755357
7bit function codesource indexsource index3 bit function codedestination index7bit operation code OP

Example

For xor of t1 and t2 and stored into t0:

  • 0000000 - funct7
  • 00111 - rs2
  • 00110 - rs1
  • 100 - funct3
  • 00101 - rd
  • 0110011 - opcode

Which gives: 0x007342B3 as 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):

immrs1funct3rdopcode
125357
12-bit immediatesource index3bit functiondestination indexoperation code OP-IMM

For shifting we have:

funct7immrs1funct3rdopcode
755357
7 bit function5-bit immediatesource index3 bit functiondestination indexoperation code OP-IMM

U type

U-type — Upper Immediate

Is in the format:

immrdopcode
2057
20-bit immediatedestination indexoperation 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

06.4 Memory