G8.1.1 Register File with a Hard-Wired Zero

MediumImplementIcarus · browser samples / server checksReview the topic

Build an eight-word register file with two read ports in which register 0 always reads zero.

Hardware context: An eight-word register file of a small processor, with two read ports and a fixed zero register. Build the register file whose register 0 reads zero and ignores every write.

A small processor keeps its working values in a register file. One instruction reads two registers and writes one. Many processors fix register 0 to the value zero, so every instruction has a free constant.

This is an Implement problem. Write regfile8: eight registers of 8 bits, one write port and two read ports.

The write port works at the rising clock edge. When we is 1, the register at waddr takes wdata. A write to register 0 changes nothing.

The two read ports use no clock. Each one shows the stored word of its address in the same cycle. Address 0 always reads 00. A read in the cycle of a write to the same register still shows the old word.

Signals in the Timeline

SignalWidthRole
writes96input of each check
reads90input of each check
Full specification
The module you write (keep the name and the ports)
module regfile8 (
  input  logic       clk,
  input  logic       we,        // 1: write wdata to register waddr at the next rising edge
  input  logic [2:0] waddr,
  input  logic [7:0] wdata,
  input  logic [2:0] raddr_a,
  output logic [7:0] rdata_a,
  input  logic [2:0] raddr_b,
  output logic [7:0] rdata_b
);
  // your design
endmodule
PortRule
WriteAt a rising edge with we = 1 and waddr from 1 to 7, the register at waddr takes wdata.
Write to register 0Ignored. Register 0 never holds anything but zero.
Read (both ports)rdata follows its address with no clock: the word stored in that register now.
Read of address 0Always 00, from the first moment, before any write.
Read during a writeThe read shows the old word until the edge. The new word shows after the edge.

The file has no reset. Each test first writes the word f0 + k to every register k, and tries the same on register 0. Then it applies up to eight writes. Then it runs five cycles in which a write may happen while both ports read.

Both ports are sampled 1 ns before each of those five edges. The result fields are named c0_rdata_a and c0_rdata_b for the first cycle, up to c4_rdata_a and c4_rdata_b.

Examples

Example 1

Read the Fill, Then Three Written Registers
Input
After the fill. Writes: 3<-3c, 5<-99, 7<-c5. Then: no write, read 1 and 2; no write, read 3 and 5; no write, read 7 and 4; no write, read 6 and 3; no write, read 5 and 5
Output
c0_rdata_a = 0xf1, c0_rdata_b = 0xf2, c1_rdata_a = 0x3c, c1_rdata_b = 0x99, c2_rdata_a = 0xc5, c2_rdata_b = 0xf4, c3_rdata_a = 0xf6, c3_rdata_b = 0x3c, c4_rdata_a = 0x99, c4_rdata_b = 0x99

Registers 1, 2, 4 and 6 still hold their fill words f1, f2, f4 and f6. Registers 3, 5 and 7 hold what the test wrote. Both ports may read the same register in one cycle.

Example 2

Register 0
Input
After the fill. Writes: 0<-aa, 1<-11, 0<-55. Then: no write, read 0 and 1; no write, read 1 and 0; no write, read 0 and 0; write 0<-ee, read 0 and 7; no write, read 0 and 7
Output
c0_rdata_a = 0x0, c0_rdata_b = 0x11, c1_rdata_a = 0x11, c1_rdata_b = 0x0, c2_rdata_a = 0x0, c2_rdata_b = 0x0, c3_rdata_a = 0x0, c3_rdata_b = 0xf7, c4_rdata_a = 0x0, c4_rdata_b = 0xf7

The fill and two more writes all try to change register 0. Both ports still read 00 from address 0. In cycle 3 a write to register 0 is on the port while port A reads it: still 00.

Example 3

A Read in the Cycle of the Write
Input
After the fill. Writes: 4<-44. Then: no write, read 4 and 6; write 4<-a4, read 4 and 6; no write, read 4 and 6; write 6<-b6, read 2 and 6; no write, read 6 and 2
Output
c0_rdata_a = 0x44, c0_rdata_b = 0xf6, c1_rdata_a = 0x44, c1_rdata_b = 0xf6, c2_rdata_a = 0xa4, c2_rdata_b = 0xf6, c3_rdata_a = 0xf2, c3_rdata_b = 0xf6, c4_rdata_a = 0xb6, c4_rdata_b = 0xf2

In cycle 1 the test writes a4 to register 4 while port A reads it. Port A shows the old word 44, because the read is sampled before the edge. In cycle 2 it shows a4.

Constraints and Contract

  • Inputs change after an edge and are known 0/1 values. Each test writes every register before it reads.
  • Keep the module name and the ports.

Hints

Hint 1

There are two places to deal with register 0: the write port and the read ports. Decide what each place must do.

Hint 2

If you only block the write, word 0 of the array is never written. Think about what a word that was never written reads as.

Hint 3

Give each read port one continuous assignment. When the address is 0 it gives the constant 00. Otherwise it gives the array word. The write block needs we and an address that is not 0.

What the grader checks: Eight directed and eight seeded scripts run on the file. Each one fills every register and applies up to eight writes. Then it runs five cycles that mix writes with reads on both ports. Both ports are sampled before every edge and compared with a model written in JavaScript. A read of a register that was never written is outside this problem.

16 checks on Icarus · browser samples / server checks. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain public samples only. A passing result establishes the tested cases, not a proof for all possible inputs.

See all 2 steps and the final capstone

Report a problem with this page

Your code SystemVerilogSaved locally
Ln 1, Col 1Tab indents · Ctrl/⌘ + Enter runs samples
Not run yet

Read the Fill, Then Three Written Registers

Input
After the fill. Writes: 3<-3c, 5<-99, 7<-c5. Then: no write, read 1 and 2; no write, read 3 and 5; no write, read 7 and 4; no write, read 6 and 3; no write, read 5 and 5
Expected output
c0_rdata_a = 0xf1, c0_rdata_b = 0xf2, c1_rdata_a = 0x3c, c1_rdata_b = 0x99, c2_rdata_a = 0xc5, c2_rdata_b = 0xf4, c3_rdata_a = 0xf6, c3_rdata_b = 0x3c, c4_rdata_a = 0x99, c4_rdata_b = 0x99

Registers 1, 2, 4 and 6 still hold their fill words f1, f2, f4 and f6. Registers 3, 5 and 7 hold what the test wrote. Both ports may read the same register in one cycle.

Run samples executes all 3 public checks. Check all tests runs 16 checks on the server.

Icarus · browser samples / server checks