-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathalu.sv
29 lines (25 loc) · 768 Bytes
/
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
`timescale 1ns / 1ps
module alu#(
parameter DATA_WIDTH = 32,
parameter OPCODE_LENGTH = 4
)
(
input logic [DATA_WIDTH-1:0] SrcA,
input logic [DATA_WIDTH-1:0] SrcB,
input logic [OPCODE_LENGTH-1:0] Operation,
output logic[DATA_WIDTH-1:0] ALUResult
);
always_comb
begin
case(Operation)
4'b0000: // AND
ALUResult = SrcA & SrcB;
4'b0010: // ADD
ALUResult = $signed(SrcA) + $signed(SrcB);
4'b1000: // Equal
ALUResult = (SrcA == SrcB) ? 1 : 0;
default:
ALUResult = 0;
endcase
end
endmodule