@@ -25,16 +25,18 @@ module lw_tb;
2525 initial begin
2626 reset <= `TRUE ;
2727
28- // set up instructions and data memory
28+ // set up instructions and data memory; M array uses word addressing, hence the indices there
29+ // are 4 times smaller than the actual addresses corresponding to the beginning to the
30+ // corresponding word
2931 uut.memory.M [ 0 ] = 32'h00012083 ; // lw x1, 0(x2)
30- uut.memory.M [ 4 ] = 32'h00412083 ; // lw x1, 4(x2)
31- uut.memory.M [ 8 ] = 32'hff812083 ; // lw x1, -8(x2)
32- uut.memory.M [34 ] = 32'hbadab00f ; // have some data at address 34
33- uut.memory.M [42 ] = 32'hdeadbeef ; // have some data at address 42
34- uut.memory.M [46 ] = 32'hcafebabe ; // have some data at address 46
32+ uut.memory.M [ 1 ] = 32'h00412083 ; // lw x1, 4(x2)
33+ uut.memory.M [ 2 ] = 32'hff812083 ; // lw x1, -8(x2)
34+ uut.memory.M [40 ] = 32'hbadab00f ; // have some data at address 0xa0
35+ uut.memory.M [42 ] = 32'hdeadbeef ; // have some data at address 0xa8
36+ uut.memory.M [43 ] = 32'hcafebabe ; // have some data at address 0xac
3537
3638 // set up register file
37- uut.instruction_decode.instanceRegFile.RFMem[2 ] = 42 ; // x2 = 42
39+ uut.instruction_decode.instanceRegFile.RFMem[2 ] = 32'ha8 ; // x2 = 42 * 4 = 168 = 0xa8
3840
3941 wait_till_next_cfsm_state (uut.control_fsm.FETCH );
4042
@@ -49,15 +51,15 @@ module lw_tb;
4951
5052 wait_till_next_cfsm_state (uut.control_fsm.MEMADR );
5153
52- `assert_equal (uut.instruction_decode.instanceRegFile.RFMem[2 ], 42 )
53- `assert_equal (uut.alu.a, 42 )
54+ `assert_equal (uut.instruction_decode.instanceRegFile.RFMem[2 ], 32'ha8 )
55+ `assert_equal (uut.alu.a, 32'ha8 )
5456 `assert_equal (uut.alu.b, 0 )
55- `assert_equal (uut.alu.out, 42 )
57+ `assert_equal (uut.alu.out, 32'ha8 )
5658
5759 wait_till_next_cfsm_state (uut.control_fsm.MEMREAD );
5860
59- `assert_equal (uut.result, 42 )
60- `assert_equal (uut.memory_address, 42 )
61+ `assert_equal (uut.result, 32'ha8 )
62+ `assert_equal (uut.memory_address, 32'ha8 )
6163
6264 wait_till_next_cfsm_state (uut.control_fsm.MEMWB );
6365
@@ -67,7 +69,7 @@ module lw_tb;
6769 wait_till_next_cfsm_state (uut.control_fsm.FETCH );
6870
6971 `assert_equal (uut.instruction_decode.instanceRegFile.RFMem[1 ], 32'hdeadbeef )
70- `assert_equal (uut.instruction_decode.instanceRegFile.RFMem[2 ], 42 )
72+ `assert_equal (uut.instruction_decode.instanceRegFile.RFMem[2 ], 32'ha8 )
7173 `assert_equal (uut.fetch.pc_cur, 4 ) // starting second instruction already
7274
7375 wait_till_next_cfsm_state (uut.control_fsm.DECODE );
@@ -79,15 +81,15 @@ module lw_tb;
7981
8082 wait_till_next_cfsm_state (uut.control_fsm.MEMADR );
8183
82- `assert_equal (uut.instruction_decode.instanceRegFile.RFMem[2 ], 42 )
83- `assert_equal (uut.alu.a, 42 )
84+ `assert_equal (uut.instruction_decode.instanceRegFile.RFMem[2 ], 32'ha8 )
85+ `assert_equal (uut.alu.a, 32'ha8 )
8486 `assert_equal (uut.alu.b, 4 )
85- `assert_equal (uut.alu.out, 46 )
87+ `assert_equal (uut.alu.out, 32'hac )
8688
8789 wait_till_next_cfsm_state (uut.control_fsm.MEMREAD );
8890
89- `assert_equal (uut.result, 46 )
90- `assert_equal (uut.memory_address, 46 )
91+ `assert_equal (uut.result, 32'hac )
92+ `assert_equal (uut.memory_address, 32'hac )
9193
9294 wait_till_next_cfsm_state (uut.control_fsm.MEMWB );
9395
@@ -97,7 +99,7 @@ module lw_tb;
9799 wait_till_next_cfsm_state (uut.control_fsm.FETCH );
98100
99101 `assert_equal (uut.instruction_decode.instanceRegFile.RFMem[1 ], 32'hcafebabe )
100- `assert_equal (uut.instruction_decode.instanceRegFile.RFMem[2 ], 42 )
102+ `assert_equal (uut.instruction_decode.instanceRegFile.RFMem[2 ], 32'ha8 )
101103 `assert_equal (uut.fetch.pc_cur, 8 ) // starting third instruction already
102104
103105 wait_till_next_cfsm_state (uut.control_fsm.DECODE );
@@ -109,15 +111,15 @@ module lw_tb;
109111
110112 wait_till_next_cfsm_state (uut.control_fsm.MEMADR );
111113
112- `assert_equal (uut.instruction_decode.instanceRegFile.RFMem[2 ], 42 )
113- `assert_equal (uut.alu.a, 42 )
114+ `assert_equal (uut.instruction_decode.instanceRegFile.RFMem[2 ], 32'ha8 )
115+ `assert_equal (uut.alu.a, 32'ha8 )
114116 `assert_equal (uut.alu.b, - 8 )
115- `assert_equal (uut.alu.out, 34 )
117+ `assert_equal (uut.alu.out, 32'ha0 )
116118
117119 wait_till_next_cfsm_state (uut.control_fsm.MEMREAD );
118120
119- `assert_equal (uut.result, 34 )
120- `assert_equal (uut.memory_address, 34 )
121+ `assert_equal (uut.result, 32'ha0 )
122+ `assert_equal (uut.memory_address, 32'ha0 )
121123
122124 wait_till_next_cfsm_state (uut.control_fsm.MEMWB );
123125
@@ -127,9 +129,10 @@ module lw_tb;
127129 wait_till_next_cfsm_state (uut.control_fsm.FETCH );
128130
129131 `assert_equal (uut.instruction_decode.instanceRegFile.RFMem[1 ], 32'hbadab00f )
130- `assert_equal (uut.instruction_decode.instanceRegFile.RFMem[2 ], 42 )
132+ `assert_equal (uut.instruction_decode.instanceRegFile.RFMem[2 ], 32'ha8 )
131133 `assert_equal (uut.fetch.pc_cur, 12 )
132134
135+ $finish ;
133136 end
134137
135138 `SETUP_VCD_DUMP (lw_tb)
0 commit comments