-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathALU.v
More file actions
73 lines (58 loc) · 1.08 KB
/
Copy pathALU.v
File metadata and controls
73 lines (58 loc) · 1.08 KB
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
module ALU(Output,CarryOut,InputA,InputB,ALUControl,Zero);
output reg [31:0] Output;
input[31:0] InputA,InputB;
input[1:0]ALUControl;
wire [31:0] CarryOuts;
output CarryOut;
output reg Zero;
/*ALU opcodes
Add 00
Sub 10
Xor 01
*/
always @(*)
begin
if(ALUControl == 2'b00)
begin
Output = InputA + InputB;
Zero = 1'b0;
end
else if(ALUControl == 2'b10)
begin
Output = InputA - InputB;
if(Output == 32'b0)
Zero = 1'b1;
else
Zero = 1'b0;
end
else
begin
Output = InputA ^ InputB;
Zero = 1'b0;
end
end
//The above code has the same implementation as the whole code below except for the test bench
endmodule
/*
module test();
wire[31:0] Output;
reg[31:0] InputA,InputB;
reg[1:0]ALUControl;
wire [31:0] CarryOuts;
wire CarryOut;
ALU uut(Output,CarryOut,InputA,InputB,ALUControl);
initial begin
$dumpfile ("ALU_out.vcd");
$dumpvars(0,test);
#40
ALUControl = 2'b00;
InputA = 32'd12;
InputB = 32'd4;
#40
ALUControl = 2'b10;
InputA = 32'd20;
InputB = 32'd14;
#40;
end
endmodule
*/