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

ALU Symbol
Truth Table
| Operation | Opcode | A | B | Zout |
|---|---|---|---|---|
| A + B | 000 | 1111 | 0000 | 00001111 |
| A - B | 001 | 1110 | 0010 | 00001100 |
| A or B | 010 | 1111 | 1000 | 00001111 |
| A and B | 011 | 1001 | 1000 | 00001000 |
| Not A | 100 | 1111 | 0000 | 11110000 |
| A1 * B1 | 101 | 1111 | 1111 | 11100001 |
| A nand B | 110 | 1111 | 0010 | 11111101 |
| A xor B | 111 | 0000 | 0100 | 00000100 |
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
Explore Verilog Logic Gates, Mux & Encoders
- Verilog HDL Code for All Logic Gates
- 2-to-4 Decoder (Verilog HDL Code)
- 4-to-1 Multiplexer and 1-to-4 Demultiplexer (Verilog Code)
- Verilog Code: 1-to-4 Demultiplexer
- 8-to-1 Multiplexer (Verilog HDL Code)
- 8-to-3 Encoder Without Priority (Verilog)
- 8-to-3 Priority Encoder (Verilog)
- 8-to-3 Priority Encoder (Verilog Code)
- 1-Bit and 4-Bit Comparator Design (Verilog)
Explore Verilog Flip-Flops, Counters & Registers
- T, D, SR, JK Flip Flop (Verilog HDL Code)
- D Flip Flop Synchronous Reset (Verilog)
- D Flip Flop Without Reset (Verilog)
- Verilog Code for Binary Up-Down Counter
- Verilog HDL: BCD & Gray Counters
- 4-bit Down Counter (Verilog Code Test Bench)
- 4-bit Binary Asynchronous Reset Counter (Verilog)
- 4-bit Binary Synchronous Reset Counter (Verilog)
- 4-bit BCD Asynchronous Reset Counter (Verilog)
- 4-bit BCD Synchronous Reset Counter (Verilog Code)
- 4-bit Mod-13 Counter (Verilog Code Test Bench)
- Shift Left / Shift Right Register (Verilog)
- Parallel Load Shift Left Register (Verilog Code)
- PRBS Generator (Verilog Code Test Bench)
Explore Verilog Math, Processing & Memory
- Full Adder (Verilog HDL Code)
- Verilog Code: Half Adder, Half Subtractor, Full Subtractor
- 32-Bit ALU (Verilog Code)
- RAM / ROM (Verilog Code)
- Asynchronous FIFO (Verilog Code Test Bench)
- Asynchronous FIFO Design (Verilog Code and Explanation)
- Mealy / Moore Machine (Verilog)
- Low Pass FIR Filter (Verilog Code)
- 4-bit Binary to Gray Counter Converter in Verilog
