ALU
Definition
An ALU (Arithmetic Logic Unit) is a combinational digital circuit that performs arithmetic operations and logical operations on binary numbers, according to control inputs.
It takes one or more binary inputs, applies a selected operation such as addition, subtraction, AND, OR, or comparison, and produces the corresponding output immediately based on the current input values.
Main Content
1. Arithmetic Operations in ALU
Arithmetic operations
- are mathematical operations performed on binary data. The most common arithmetic functions in an ALU are addition, subtraction, increment, decrement, and sometimes multiplication or division support in more advanced systems.
- The simplest and most important arithmetic function is binary addition. An ALU uses half adders, full adders, and adder chains to compute sum and carry outputs. For example, adding
1011and0101produces10000.
Subtraction
- is often performed using 2’s complement arithmetic. Instead of building a separate subtractor, the ALU can invert the second operand and add 1, then use the same adder hardware. This makes the circuit efficient and compact.
Incrementing and decrementing
- are useful in counters, loops, and address calculations. For instance, incrementing a program counter by 1 or decrementing a loop counter are typical ALU tasks.
- In larger processors, arithmetic operations may be optimized using fast adders such as ripple-carry adders, carry-lookahead adders, or carry-save adders, depending on speed requirements.
2. Logic Operations in ALU
Logic operations
- operate bit by bit on binary inputs. The ALU commonly performs AND, OR, NOT, XOR, NAND, NOR, and XNOR operations.
- These operations are essential in masking, setting, clearing, and toggling bits. For example, ANDing a value with
00001111can isolate the lower four bits of a byte.
XOR
- is especially useful for detecting bit differences, parity checking, and toggling bits. For example,
1 XOR 1 = 0, while1 XOR 0 = 1. - Logic operations are heavily used in decision making, data processing, and bitwise manipulation inside software and hardware.
- Because these operations are combinational, the output changes directly when the input changes, making the ALU fast and predictable.
3. ALU Structure and Control Inputs
- An ALU is usually built from a combination of arithmetic circuits, logic gates, multiplexers, and control lines. The control lines decide which operation the ALU should perform.
- A multiplexer (MUX) is often used to select one output from several possible operation outputs. For example, the ALU may generate sum, AND, OR, and XOR outputs in parallel, and the MUX selects the required one.
Control signals
- come from the control unit of the CPU. These signals tell the ALU whether to perform addition, subtraction, comparison, or a logic function.
- A basic ALU may also include status flags such as Zero (Z), Carry (C), Sign (S), and Overflow (V). These flags help determine the result of an operation. For example, if an addition result is zero, the Zero flag becomes 1.
- A simplified ALU structure can be shown as:
Input A ----->| |
| |----> Result
Input B ----->| ALU |
| |----> Flags
Control lines ->| |
The control lines choose which internal operation is passed to the output.
Working / Process
1. Inputs are applied
- The ALU receives binary operands, usually called A and B, along with control signals that specify the operation to perform.
- Example: A =
0101, B =0011, control = ADD.
2. Operation is selected and executed
- The internal logic circuits and adders compute the possible results in parallel or through selected paths.
- If the control signal indicates addition, the adder produces the sum. If it indicates AND, the logic gate network produces the bitwise AND result.
3. Output and status flags are generated
- The selected result is output immediately.
- Status flags such as carry, zero, overflow, or negative/sign are also updated.
- Example:
0101 + 0011 = 1000, so the ALU outputs1000and updates flags accordingly.
Advantages / Applications
Fast data processing
- : The ALU performs operations very quickly because it is implemented as a combinational circuit with direct output response.
Versatility
- : A single ALU can handle many tasks such as arithmetic, logic, comparison, and bit manipulation, reducing hardware complexity.
Wide use in digital systems
- : ALUs are used in microprocessors, microcontrollers, calculators, embedded systems, digital signal processors, and control units.
Summary
- ALU is the main circuit that performs arithmetic and logic on binary data.
- It works as a combinational circuit controlled by operation-select signals.
- It is essential for computing, decision-making, and bit manipulation in digital systems.
- Important terms to remember: Arithmetic operations, Logic operations, Control signals, Multiplexer, Carry, Overflow, Zero flag, 2’s complement