-
Notifications
You must be signed in to change notification settings - Fork 1
/
datapath.v
78 lines (64 loc) · 1.5 KB
/
datapath.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
`timescale 1ns / 1ps
module datapath(
input clk,
input rstPC,
input [31:0] instruction,
input readDataFromMem,
output ALUOutput,
output writeDataToMem
);
// wires of ALU
wire [31:0] ALUInput;
// instantiating alu
alu alu_inst (
.a (readData1),
.b (ALUInput),
.opcode (ALUCtrl),
.zero (zero),
.result(ALUOutput)
);
// control unit output wires.
wire [3:0] ALUCtrl;
wire [1:0] ALUOp;
wire ALUSrc;
wire branch;
wire memToReg;
wire memWrite;
wire memRead;
wire regDest;
wire regWrite;
// instantiating control unit
control_unit control_unit_inst (
.instruction(instruction),
.ALUCtrl(ALUCtrl),
.ALUOp(ALUOp),
.regDest(regDest),
.regWrite(regWrite),
.ALUSrc(ALUSrc),
.memWrite(memWrite),
.memRead(memRead),
.memToReg(memToReg),
.branch(branch)
);
// wires of register file
wire [4:0] writeReg;
wire [31:0] writeData;
wire [31:0] readData1;
wire [31:0] readData2;
// assign wires to register file
assign writeReg = regDest ? instruction[15:11] : instruction[20:16];
assign writeData = memToReg ? readDataFromMem : ALUOutput ;
// instantiating register file
register_file register_file_inst (
.readAddr1(instruction[25:21]),
.readAddr2(instruction[20:16]),
.writeAddr(writeReg),
.writeData(writeData),
.writeEn(regWrite),
.clk(clk),
.readData1(readData1),
.readData2(readData2)
);
// assigning write to memory wires
assign writeDataToMem = readData2;
endmodule