-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtb_alu.v
More file actions
48 lines (39 loc) · 959 Bytes
/
tb_alu.v
File metadata and controls
48 lines (39 loc) · 959 Bytes
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
/* A RISC-V core designed to use minimal area.
Aim is to support RV32E
*/
module tb_alu (
input clk,
input rstn,
input [3:0] op,
input [31:0] a,
input [31:0] b,
output reg [31:0] d
);
`ifdef COCOTB_SIM
initial begin
$dumpfile ("alu.vcd");
$dumpvars (0, tb_alu);
#1;
end
`endif
reg [4:0] counter = 0;
wire [4:0] next_counter = counter + 1;
always @(posedge clk)
if (!rstn)
counter <= 0;
else
counter <= next_counter;
reg cy;
wire cy_in = (counter == 0) ? (op[1] || op[3]) : cy;
wire op_res, cy_out, lts;
nanoV_alu alu(op, a[counter], b[counter], cy_in, op_res, cy_out, lts);
always @(posedge clk) begin
d[counter] <= op_res;
cy <= cy_out;
if (counter == 5'b11111)
if (op[2:0] == 3'b011)
d[0] <= ~cy_out;
else if (op[2:0] == 3'b010)
d[0] <= lts;
end
endmodule