Implementation

Implementation Overview

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!

Basic Elements

PC

PC is just a 32-bit register.

circle-info
  • 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?

Memory

circle-exclamation

Instruction Memory

For simplicity, IMEM is not writable, i.e, it's a ROM.

Check my implementationarrow-up-right here.

Data Memory

Data memory should be synchronous write and asynchronous read RAM.

circle-info

How to support sb, sh and sw?

Check my implementationarrow-up-right.

Register File

Our register file should be synchronous write and asynchronous read.

circle-exclamation

Check my implementionarrow-up-right.

ALU

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

circle-exclamation

Here is my implementationarrow-up-right.

Immediate Generator

My implementation goes herearrow-up-right.

Comparator

Pretty easy and here is my implementationarrow-up-right.

Control Unit

RV32I is basically a nine bit ISA. If you get stuck, check my implementationarrow-up-right.

Connect all the components

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.

Test our implementations

I write some very simple testbenches to test my implementations, you can see these testbench at single-cycle/simarrow-up-right

Last updated