-
Notifications
You must be signed in to change notification settings - Fork 1
/
DATAPATH_TEST.vhd
209 lines (175 loc) · 4.84 KB
/
DATAPATH_TEST.vhd
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
ENTITY DATAPATH_TEST IS
END DATAPATH_TEST;
ARCHITECTURE behavior OF DATAPATH_TEST IS
-- Component Declaration for the Unit Under Test (UUT)
COMPONENT DATAPATH
PORT(
nPC_sel : in STD_LOGIC;-- -- =0 pc+4 =1 pc+4+signExt*4
PC_LdEn : in STD_LOGIC;--- =1
RegWr : in STD_LOGIC; -- RF_Wren
RegDst : in STD_LOGIC;--RF_B_Sel selects rd or rt
ExtOp : in STD_LOGIC_VECTOR(1 downto 0); ---- Extension Operation
ALUSrc : in STD_LOGIC;--selects Rf_B or Immediate
ALUctr : in STD_LOGIC_VECTOR(3 downto 0);--AluFunc praksh ths alu
MemWr : in STD_LOGIC;---- write Enable for control
MemtoReg : in STD_LOGIC;----RF_WrData_Sel select ALU_out or MEM_out
Mux_Sel_RFA : in std_logic; --select RFA or 00000 for lui li and b
Clk : in STD_LOGIC;
Reset : in STD_LOGIC;
Instruction : out STD_LOGIC_VECTOR (31 downto 0);
Zero : out STD_LOGIC);
END COMPONENT;
--Inputs
signal nPC_sel : std_logic := '0';
signal PC_LdEn : std_logic := '0';
signal RegWr : std_logic := '0';
signal RegDst : std_logic := '0';
signal ExtOp : std_logic_vector(1 downto 0) := (others => '0');
signal ALUSrc : std_logic := '0';
signal ALUctr : std_logic_vector(3 downto 0) := (others => '0');
signal MemWr : std_logic := '0';
signal MemtoReg : std_logic := '0';
signal Mux_Sel_RFA : std_logic := '0';
signal Clk : std_logic := '0';
signal Reset : std_logic := '0';
--Outputs
signal Instruction : std_logic_vector(31 downto 0);
signal Zero : std_logic;
-- Clock period definitions
constant Clk_period : time := 10 ns;
BEGIN
-- Instantiate the Unit Under Test (UUT)
uut: DATAPATH PORT MAP (
nPC_sel => nPC_sel,
PC_LdEn => PC_LdEn,
RegWr => RegWr,
RegDst => RegDst,
ExtOp => ExtOp,
ALUSrc => ALUSrc,
ALUctr => ALUctr,
MemWr => MemWr,
MemtoReg => MemtoReg,
Mux_Sel_RFA => Mux_Sel_RFA,
Clk => Clk,
Reset => Reset,
Instruction => Instruction,
Zero => Zero
);
-- Clock process definitions
Clk_process :process
begin
Clk <= '0';
wait for Clk_period/2;
Clk <= '1';
wait for Clk_period/2;
end process;
-- Stimulus process
stim_proc: process
begin
-- Reset <= '1' ;
-- wait for Clk_period*7;
-- ----addi $r5,$r1,8-------------------
-- nPC_sel <= '0' ;
-- PC_LdEn <= '1';
-- RegWr<= '1';
-- RegDst <= '0' ; --- 0 for I-type
-- ExtOp <= "00"; --signExt(Imm)
-- ALUSrc <= '1'; -- ALU_Bin_Sel
-- ALUctr <= "0000";--add operation for alu
-- MemWr <= '0'; --doesnt do store instr
-- MemtoReg <='0'; --take ALU_out
-- Mux_Sel_RFA <= '0'; --take RF_A
-- Reset <= '0' ;
--
-- -- hold reset state for 100 ns.
Reset <= '1';
wait for clk_period*1;
nPC_sel <='0';
PC_LdEn <='1';
Reset <= '0';
wait for clk_period*1;
--wait for 10 ns ;
Reset <= '0';
-- addi r5,r0,8
--RF[rd] = RF[rs] + SignExtend(Imm)
nPC_sel <='0';
PC_LdEn<='1';
RegWr <='1';
MemtoReg <='0'; --Alu out
RegDst <='0';
ExtOp<="00"; -- SIGN EXT
ALUSrc <='1'; --Immed
ALUctr <="0000"; --add
MemWr <='0';
Mux_Sel_RFA<='0';
wait for clk_period*1;
-- ori r3,r0,ABCD
-- RF[rd] = RF[rs] | ZeroFill(Imm)
nPC_sel <='0';
PC_LdEn <='1';
RegWr <='1';
MemtoReg <='0'; --Alu out
RegDst <='0';
ExtOp<="10"; --zero fill
ALUSrc <='1'; --Immed
ALUctr <="0011"; --OR
MemWr <='0';
Mux_Sel_RFA<='0';
wait for clk_period*1;
-- sw r3 4(r0)
-- MEM[RF[rs] + SignExtend(Imm)] <- RF[rd]
nPC_sel <='0';
PC_LdEn <='1';
RegWr <='0';
MemtoReg <='1'; --Mem out dont care
RegDst <='1';
ExtOp<="00";
ALUSrc <='1'; --Immed
ALUctr <="0000"; --add
MemWr <='1';
Mux_Sel_RFA<='0';
wait for clk_period*1;
-- lw r10,-4(r5)
--RF[rd] = MEM[RF[rs] + SignExtend(Imm)]
nPC_sel <='0';
PC_LdEn <='1';
RegWr <='1';
MemtoReg <='1'; --Mem out
RegDst <='0';
ExtOp<="00";
ALUSrc <='1'; --Immed
ALUctr <="0000";--add
MemWr <='0';
Mux_Sel_RFA<='0';
wait for clk_period*1;
-- lb r16 4(r0)
-- RF[rd] = ZeroFill(31 downto 8) & MEM[RF[rs] +SignExtend(Imm)](7 downto 0)
nPC_sel <='0';
PC_LdEn <='1';
RegWr <='1';
MemtoReg <='1'; --Mem out
RegDst <='0';
ExtOp<="00";
ALUSrc <='1'; --Immed
ALUctr <="0000"; --add
MemWr <='0';
Mux_Sel_RFA<='0';
wait for clk_period*1;
-- nand r4,r0,r16
--RF[rd] = RF[rs] NAND RF[rt]
nPC_sel <='0';
PC_LdEn <='1';
RegWr <='1';
MemtoReg <='1'; --Mem out
RegDst <='1'; --rt
ExtOp<="00"; -- dont care
ALUSrc <='0'; --RF_B
ALUctr <="0000"; --nand
MemWr <='0';
Mux_Sel_RFA<='0';
wait;
wait;
end process;
END;