Architecture

ALU (Arithmetic Logic Unit)

A combinational circuit that performs arithmetic and logical operations on binary data.

Detailed Explanation

The ALU is the computational heart of a processor. It accepts two operands and an operation selector, producing a result and status flags (zero, negative, overflow, carry). Arithmetic operations include addition, subtraction, and comparison. Logical operations include AND, OR, XOR, and NOT.

ALU design involves trade-offs between speed, area, and power. Simple ALUs use ripple-carry adders; high-performance designs employ carry-lookahead or carry-select adders. The operation selector typically uses a multiplexer to choose between operation results.

Code Example

systemverilog
module alu #(parameter WIDTH = 32) (
  input  logic [WIDTH-1:0] a, b,
  input  logic [2:0]       op,
  output logic [WIDTH-1:0] result,
  output logic             zero
);
  always_comb begin
    case (op)
      3'b000: result = a + b;      // ADD
      3'b001: result = a - b;      // SUB
      3'b010: result = a & b;      // AND
      3'b011: result = a | b;      // OR
      3'b100: result = a ^ b;      // XOR
      default: result = '0;
    endcase
  end
  assign zero = (result == '0);
endmodule