-
Notifications
You must be signed in to change notification settings - Fork 0
/
ALU.sv
66 lines (45 loc) · 1.02 KB
/
ALU.sv
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
module ALU ( A, B, s, Q );
input [2:0] s;
input [15:0] A, B;
output logic [15:0] Q;
always @*
case(s)
0: Q = 16'd0;
1: Q = (A + B);
2: if (A < B)
Q = (B - A); // works
else
Q = (A - B);
3: Q = A;
4: Q = (A ^ B);
5: Q = (A | B); // works
6: Q = (A & B);
7: Q = (A + 16'd1);
endcase
endmodule
module ALU_tb();
logic [2:0] s;
logic [15:0] A, B;
logic [15:0] Q;
ALU DUT ( A, B, s, Q );
initial begin
//integer i;
A = 16'd10; B = 16'd11; s = 3'd0; #30;
A = 16'd10; B = 16'd11; s = 3'd1; #30;
A = 16'd10; B = 16'd11; s = 3'd2; #30;
A = 16'd10; B = 16'd11; s = 3'd3; #30;
A = 16'd10; B = 16'd11; s = 3'd4; #30;
A = 16'd10; B = 16'd11; s = 3'd5; #30;
A = 16'd10; B = 16'd11; s = 3'd6; #30;
A = 16'd10; B = 16'd11; s = 3'd7; #30;
/*
for(i = 0; i < 8; i++) begin
{A, B, s} = $random;
#10;
end
end
*/
end
initial
$monitor($time,,,A,,,B,,,s,,,Q);
endmodule