-
Notifications
You must be signed in to change notification settings - Fork 0
/
ALU.v
55 lines (50 loc) · 1.13 KB
/
ALU.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
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 01:51:57 06/27/2019
// Design Name:
// Module Name: ALU
// Project Name:
// Target Devices:
// Tool versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module ALU(
input [31:0]a, [31:0]b, [1:0]control,
output reg [31:0]result, output reg zFlag);
initial
begin
result = 32'b0;
end
always @(a,b,control)
begin
result = 32'b0;
case (control)
2'b00 : result = a & b; //AND
2'b01 : result = a ^ b; //XOR
2'b10 : result = a + b; //ADD
2'b11 : result = a - b; //SUB
default: result = 32'bz;
endcase
end
always @(a,b,control)
begin
if (a==b)
begin
zFlag = 1'b1;
end
else
begin
zFlag = 1'b0;
end
end
endmodule