-
Notifications
You must be signed in to change notification settings - Fork 0
/
ALU_tb.v
70 lines (59 loc) · 1.51 KB
/
ALU_tb.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
`timescale 1ns / 1ps
module ALU_tb;
// Inputs
reg [31:0] A, B, Accumulator;
reg [3:0] ALUControl;
// Outputs
wire Carry, OverFlow, Zero, Negative;
wire [31:0] Result;
// Instantiate the ALU module
ALU uut (
.A(A),
.B(B),
.Accumulator(Accumulator),
.ALUControl(ALUControl),
.Carry(Carry),
.OverFlow(OverFlow),
.Zero(Zero),
.Negative(Negative),
.Result(Result)
);
initial begin
// Initialize Inputs
A = 0;
B = 0;
Accumulator = 0;
ALUControl = 0;
// Test Addition
A = 32'd15;
B = 32'd10;
ALUControl = 3'b000;
#10; // Wait for 10 ns
// Test Subtraction
A = 32'd20;
B = 32'd15;
ALUControl = 3'b001;
#10;
// Test AND
A = 32'b10101010101010101010101010101010;
B = 32'b01010101010101010101010101010101;
ALUControl = 3'b010;
#10;
// Test OR
A = 32'b10101010101010101010101010101010;
B = 32'b01010101010101010101010101010101;
ALUControl = 3'b011;
#10;
// Test MAC
A = 32'd5;
B = 32'd3;
Accumulator = 32'd7; // Starting value in the accumulator
ALUControl = 3'b100;
#10;
// Add more test cases as needed
end
initial begin
$dumpfile("ALU.vcd");
$dumpvars(0);
end
endmodule