This project implements a configurable arithmetic logic unit (ALU) with multiple operations selectable via a 16-bit instruction input. It processes two 8-bit data inputs and produces four 8-bit outputs, along with status flags.
top.sv
├── shift_right.sv
├── shift_left.sv
├── add.sv
├── sub.sv
├── and_gate.sv
├── or_gate.sv
├── xor_gate.sv
├── special.sv
├── comp_eq.sv
├── mux4.sv
└── demux4.sv
instruction[15:0]: 16-bit control worddata0[7:0]: First 8-bit data inputdata1[7:0]: Second 8-bit data input
out0[7:0]toout3[7:0]: Four 8-bit output channelsof: Overflow flag (from addition operation)zf: Zero flag (output is zero)
00: Route toout001: Route toout110: Route toout211: Route toout3
00: Arithmetic operations (mux0 output)01: Logical operations (mux1 output)10: Constant zero11: Special operation result
00: Right shift01: Left shift10: Addition11: Subtraction
00: AND01: OR10: XOR11: Constant 1
- Right shift:
data0 >> data1 - Left shift:
data0 << data1
- Addition:
data0 + data1(with overflow flag) - Subtraction:
data0 - data1
- Bitwise AND:
data0 & data1 - Bitwise OR:
data0 | data1 - Bitwise XOR:
data0 ^ data1
- Checks if all four corner bits (LSB and MSB of both inputs) are equal
- Returns
1if true,0otherwise
- Constant
0output - Constant
1output (via logical operations only)
of: Overflow Flag – Set when addition operation overflowszf: Zero Flag – Set when the selected output equals zero
The following test bench module can be found within the source code and can be simulated with software such as Vivado.
`timescale 1ns / 1ps
module tb();
logic [15:0]instruction;
logic [7:0]data0, data1, out0, out1, out2, out3;
logic of, zf;
top dut(instruction, data0, data1, out0, out1, out2, out3, of, zf);
initial begin
instruction = 0;
data0 = 0;
data1 = 0;
#10
instruction = 16'b1111111111111111;
#10
data0 = 255;
data1 = 255;
#10
instruction = 16'b0000100000000000;
data0 = 1;
data1 = 1;
#5
data0 = 75;
#5
data1 = 25;
#10
$stop;
end
endmodule- All operations are combinational and complete in zero time
- Timescale:
1ns/1psprecision
- SystemVerilog-compliant simulator (Vivado, ModelSim, VCS)
- All source files must be compiled together
This is purely a combinational circuit and has no clock input.