Implementation
Last updated
Last updated
First, we will implement the basic elements, i.e., PC, memory, register file, ALU and so on. Then we will connect these basic elements together with our control unit. The control unit will be super easy to implement, because RV32I is basically a nine-bit ISA!
PC is just a 32-bit register.
Only the low bits of PC are useful, because the instruction memory is limited.
The low two bits of PC are always zero, how to utilize it?
To implement a single-cycle processor, we need asynchronous read instruction and data memory.
For simplicity, IMEM is not writable, i.e, it's a ROM.
Check my implementation here.
Data memory should be synchronous write and asynchronous read RAM.
How to support sb
, sh
and sw
?
Check my implementation.
Our register file should be synchronous write and asynchronous read.
Remember x0 is wired to 0.
Check my implemention.
ALU should support following operations:
ADD: y = a + b
SUB: y = a - b
AND: y = a & b
OR: y = a | b
XOR: y = a ^ b
SLL: y = a << b
SRL: y = a >> b
SRA: y = $signed(a) >>> b
SLT: y = ($signed(a) < $signed(b)) ? 1 : 0
SLTU: y = (a < b) ? 1 : 0
When doing shift, only the low 5 bits of b are useful.
Here is my implementation.
My implementation goes here.
Pretty easy and here is my implementation.
RV32I is basically a nine bit ISA. If you get stuck, check my implementation.
It's not very hard to connect all the components. If you don't know what to do, check the complete datapath we have built.
I write some very simple testbenches to test my implementations, you can see these testbench at single-cycle/sim