Skip to content

Commit ce9e284

Browse files
committed
split registers into modules
1 parent 665f627 commit ce9e284

File tree

9 files changed

+91
-29
lines changed

9 files changed

+91
-29
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
`timescale 1ns/1ps
2+
3+
module ex_mem_register (
4+
input wire clk,
5+
input wire reset,
6+
input wire en,
7+
input wire [95:0] d,
8+
output reg [95:0] q
9+
);
10+
11+
always @(posedge clk or posedge reset) begin
12+
if (reset)
13+
q <= {96{1'b0}};
14+
else if (en)
15+
q <= d;
16+
end
17+
18+
endmodule

pipelined/modules/param_register.v renamed to pipelined/modules/id_ex_register.v

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
`timescale 1ns/1ps
22

3-
module param_register #(parameter WIDTH = 1) (
3+
module id_ex_register (
44
input wire clk,
55
input wire reset,
66
input wire en,
7-
input wire [WIDTH-1:0] d,
8-
output reg [WIDTH-1:0] q
7+
input wire [229:0] d,
8+
output reg [229:0] q
99
);
1010

1111
always @(posedge clk or posedge reset) begin
1212
if (reset)
13-
q <= {WIDTH{1'b0}};
13+
q <= {230{1'b0}};
1414
else if (en)
1515
q <= d;
1616
end

pipelined/modules/if_id_register.v

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
`timescale 1ns/1ps
2+
3+
module if_id_register (
4+
input wire clk,
5+
input wire reset,
6+
input wire en,
7+
input wire [95:0] d,
8+
output reg [95:0] q
9+
);
10+
11+
always @(posedge clk or posedge reset) begin
12+
if (reset)
13+
q <= {96{1'b0}};
14+
else if (en)
15+
q <= d;
16+
end
17+
18+
endmodule
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
`timescale 1ns/1ps
2+
3+
module mem_wb_register (
4+
input wire clk,
5+
input wire reset,
6+
input wire en,
7+
input wire [161:0] d,
8+
output reg [161:0] q
9+
);
10+
11+
always @(posedge clk or posedge reset) begin
12+
if (reset)
13+
q <= {162{1'b0}};
14+
else if (en)
15+
q <= d;
16+
end
17+
18+
endmodule

pipelined/testcases/assembler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ def generate_testbench(instructions):
227227
228228
initial begin
229229
reset = 1;
230-
#5 reset = 0;
230+
#15 reset = 0;
231231
end
232232
233233
cpu_pipelined cpu(

pipelined/verilog/cpu_pipelined.v

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
`include "modules/register_file.v"
77
`include "modules/data_memory.v"
88
`include "modules/control_unit.v"
9-
`include "modules/param_register.v"
9+
`include "modules/if_id_register.v"
10+
`include "modules/id_ex_register.v"
11+
`include "modules/ex_mem_register.v"
12+
`include "modules/mem_wb_register.v"
1013

1114
module cpu_pipelined(
1215
input clk,
@@ -37,10 +40,11 @@ module cpu_pipelined(
3740
wire [63:0] if_id_pc;
3841
wire [31:0] if_id_instruction;
3942

40-
param_register #(96) if_id(
43+
if_id_register if_id(
4144
.clk(clk),
4245
.reset(reset),
43-
.d({pc_current, instruction}),
46+
.en(1'b1),
47+
.d({pc_current, instruction}),
4448
.q({ if_id_pc, if_id_instruction})
4549
);
4650

@@ -92,9 +96,10 @@ module cpu_pipelined(
9296
wire [31:0] id_ex_instruction;
9397
wire id_ex_branch, id_ex_mem_read, id_ex_mem_write, id_ex_mem_to_reg, id_ex_reg_write, id_ex_alu_src;
9498

95-
param_register #(230) id_ex(
99+
id_ex_register id_ex(
96100
.clk(clk),
97101
.reset(reset),
102+
.en(1'b1),
98103
.d({if_id_pc, reg_read_data1, reg_read_data2, if_id_instruction, branch, mem_read, mem_write, mem_to_reg, reg_write, alu_src}),
99104
.q({id_ex_pc, id_ex_reg_read_data1, id_ex_reg_read_data2, id_ex_instruction, id_ex_branch, id_ex_mem_read, id_ex_mem_write, id_ex_mem_to_reg, id_ex_reg_write, id_ex_alu_src})
100105
);
@@ -129,9 +134,10 @@ module cpu_pipelined(
129134
wire [31:0] ex_mem_instruction;
130135
wire ex_mem_zero, ex_mem_branch, ex_mem_mem_read, ex_mem_mem_write, ex_mem_mem_to_reg, ex_mem_reg_write;
131136

132-
param_register #(294) ex_mem(
137+
ex_mem_register ex_mem(
133138
.clk(clk),
134139
.reset(reset),
140+
.en(1'b1),
135141
.d({id_ex_pc , alu_result , id_ex_reg_read_data2 , branch_target , id_ex_instruction , zero , id_ex_branch , id_ex_mem_read , id_ex_mem_write , id_ex_mem_to_reg , id_ex_reg_write}),
136142
.q({ex_mem_pc, ex_mem_alu_result, ex_mem_reg_read_data2, ex_mem_branch_target, ex_mem_instruction, ex_mem_zero, ex_mem_branch, ex_mem_mem_read, ex_mem_mem_write, ex_mem_mem_to_reg, ex_mem_reg_write})
137143
);
@@ -159,9 +165,10 @@ module cpu_pipelined(
159165
wire [31:0] mem_wb_instruction;
160166
wire mem_wb_mem_to_reg, mem_wb_reg_write;
161167

162-
param_register #(162) mem_wb(
168+
mem_wb_register mem_wb(
163169
.clk(clk),
164170
.reset(reset),
171+
.en(1'b1),
165172
.d({mem_read_data , ex_mem_alu_result, ex_mem_instruction, ex_mem_mem_to_reg, ex_mem_reg_write}),
166173
.q({mem_wb_mem_read_data, mem_wb_alu_result, mem_wb_instruction, mem_wb_mem_to_reg, mem_wb_reg_write})
167174
);

pipelined/verilog/testbench_pipelined.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module testbench_pipelined();
1717

1818
initial begin
1919
reset = 1;
20-
#5 reset = 0;
20+
#15 reset = 0;
2121
end
2222

2323
cpu_pipelined cpu(

sequential/verilog/testbench_sequential.v

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@ module testbench_sequential();
2626
);
2727

2828
initial begin
29-
cpu.imem.memory[0] = 32'b00000000101000000000001100010011;
30-
cpu.imem.memory[1] = 32'b00000000000000000000001110010011;
31-
cpu.imem.memory[2] = 32'b01000000000000000000010000010011;
32-
cpu.imem.memory[3] = 32'b00000000011000111010000000100011;
33-
cpu.imem.memory[4] = 32'b00000000011001000010000000100011;
34-
cpu.imem.memory[5] = 32'b00000000000000000000000000000000;
29+
cpu.imem.memory[0] = 32'b00000000001100000000000010010011;
30+
cpu.imem.memory[1] = 32'b00000000011100000000000100010011;
31+
cpu.imem.memory[2] = 32'b00000000000000001000100001100011;
32+
cpu.imem.memory[3] = 32'b00000000000100010000000100110011;
33+
cpu.imem.memory[4] = 32'b11111111111100001000000010010011;
34+
cpu.imem.memory[5] = 32'b11111110000000000000101011100011;
35+
cpu.imem.memory[6] = 32'b00000000000000000000000000000000;
3536
end
3637

3738

sequential/visualization/cpu-data.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ const cpuData = {
33
{
44
"time": 15000,
55
"pc": 0,
6-
"instruction": 10486547,
7-
"decodedInstruction": "addi x6, x0, 10",
6+
"instruction": 3145875,
7+
"decodedInstruction": "addi x1, x0, 3",
88
"controlSignals": {
99
"branch": false,
1010
"mem_read": false,
@@ -15,12 +15,12 @@ const cpuData = {
1515
},
1616
"registers": [
1717
0,
18+
3,
1819
0,
1920
0,
2021
0,
2122
0,
2223
0,
23-
10,
2424
0,
2525
0,
2626
0,
@@ -48,7 +48,7 @@ const cpuData = {
4848
0
4949
],
5050
"changedRegisters": [
51-
6
51+
1
5252
],
5353
"memory": [
5454
0,
@@ -308,13 +308,13 @@ const cpuData = {
308308
0,
309309
0
310310
],
311-
"aluResult": 10
311+
"aluResult": 3
312312
},
313313
{
314314
"time": 25000,
315315
"pc": 4,
316-
"instruction": 915,
317-
"decodedInstruction": "addi x7, x0, 0",
316+
"instruction": 7340307,
317+
"decodedInstruction": "addi x2, x0, 7",
318318
"controlSignals": {
319319
"branch": false,
320320
"mem_read": false,
@@ -325,13 +325,13 @@ const cpuData = {
325325
},
326326
"registers": [
327327
0,
328+
3,
329+
7,
328330
0,
329331
0,
330332
0,
331333
0,
332334
0,
333-
10,
334-
0,
335335
0,
336336
0,
337337
0,
@@ -358,7 +358,7 @@ const cpuData = {
358358
0
359359
],
360360
"changedRegisters": [
361-
7
361+
2
362362
],
363363
"memory": [
364364
0,
@@ -618,7 +618,7 @@ const cpuData = {
618618
0,
619619
0
620620
],
621-
"aluResult": 0
621+
"aluResult": 7
622622
}
623623
]
624624
};

0 commit comments

Comments
 (0)