-
Notifications
You must be signed in to change notification settings - Fork 1
/
ALU.v
36 lines (31 loc) · 869 Bytes
/
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
`timescale 1ns / 1ps
module ALU
(
input wire [7:0] data1,
input wire [7:0] data2,
input wire [3:0] ALU_control,
output reg [7:0] ALU_result,
output wire zero
);
parameter AND = 4'b0000;
parameter OR = 4'b0001;
parameter ADD = 4'b0010;
parameter XOR = 4'b0011;
parameter NOT = 4'b0100;
parameter SUBTRACT = 4'b0110;
parameter JUMP = 4'b1100;
assign zero = (ALU_result == 0) ? 1'b1 : 1'b0;
always@(*)
begin
case(ALU_control)
AND: ALU_result = data1 & data2;
OR: ALU_result = data1 | data2;
ADD: ALU_result = data1 + data2;
SUBTRACT: ALU_result = data1 - data2;
XOR: ALU_result = data1 ^ data2;
NOT: ALU_result = ~ data1;
JUMP: ALU_result = 0;
default: ALU_result = 0;
endcase
end
endmodule