Files
FPGA_Uni/modules/alu.sv
T

32 lines
1.1 KiB
Systemverilog

`include "asu.sv"
`include "lu.sv"
// flags[0:0] = Cout
// flags[1:1] = Overflow
module alu #(parameter width=2)(input logic [3:0] op,
input logic [2**width-1:0] A, input logic [2**width-1:0] B,
output logic [2**width-1:0] OUT_1, output logic flags[1:0]);
logic [2**width-1:0] asu_out;
logic [1:0] asu_flags;
asu #(width) adder_unit(asu_op[op[1]], A, B, asu_out, asu_flags[0], asu_flags[1]);
logic [2**width-1:0] lu_out;
lu #(width) logic_unit(op[1:0], A, B, lu_out);
always_comb begin
case (op)
2'b0000: begin OUT_1 = asu_out; flags = asu_flags; end
2'b0001: begin OUT_1 = asu_out; flags = asu_flags; end
2'b0010: begin OUT_1 = asu_out; flags = asu_flags; end
2'b0011: begin OUT_1 = asu_out; flags = asu_flags; end
2'b0100: OUT_1 = lu_out;
2'b0101: OUT_1 = lu_out;
2'b0110: OUT_1 = lu_out;
2'b0111: OUT_1 = lu_out;
2'b1010: OUT_1 = (asu_out[2**width-1] ^ asu_flags[1]);
2'b1011: OUT_1 = ~asu_flags[0];
default: '0;
endcase
end
endmodule