32-bit ALU Verilog Code Implementation

verilog
alu
hdl
digital design
source code

This page provides Verilog source code for a 32-bit Arithmetic Logic Unit (ALU). This ALU performs both arithmetic and logical operations.

ALU Symbol

ALU Symbol

Truth Table

OperationOpcodeABZout
A + B0001111000000001111
A - B0011110001000001100
A or B0101111100000001111
A and B0111001100000001000
Not A1001111000011110000
A1 * B11011111111111100001
A nand B1101111001011111101
A xor B1110000010000000100

Verilog Code

module ALU (
    input  [3:0] a, b, s;
    input       en;
    output reg [7:0] y
);

always @(a, b, s, en, y)
begin
    if (en == 1)
    begin
        case (s)
            4'd0: y = a + b;
            4'd1: y = a - b;
            4'd2: y = a * b;
            4'd3: y = {4'b0000, ~a};
            4'd4: y = {4'd0, (a & b)};
            4'd5: y = {4'd0, (a | b)};
            4'd6: y = {4'd0, (a ^ b)};
            4'd7: y = {4'd0, ~(a & b)};
            4'd8: y = {4'd0, ~(a | b)};
            4'd9: y = {4'd0, ~(a ^ b)};
            default: begin end
        endcase
    end
    else
        y = 8'd0;
end

endmodule
Verilog Code for 1 to 4 Demultiplexer

Verilog Code for 1 to 4 Demultiplexer

This article provides Verilog source code for a 1 to 4 DEMUX, accompanied by a block diagram and truth table for enhanced understanding.

verilog
demultiplexer
digital logic