ALU
Definition
An Arithmetic Logic Unit (ALU) is a fundamental combinational logic circuit inside the CPU that performs arithmetic operations such as addition and subtraction, and logic operations such as AND, OR, NOT, XOR, comparison, and shifting-related functions. It takes binary inputs, processes them according to control signals, and produces a binary output along with status flags like carry, zero, and overflow.
An ALU is called a combinational circuit because its output depends only on the current input values, not on any memory of previous inputs. It is one of the most important building blocks of digital computers and microprocessors.
Main Content
1. Basic Structure and Function of ALU
- An ALU is made up of several interconnected logic circuits that can perform different operations on binary data.
- It receives:
- Operand inputs: the binary numbers to be processed
- Control inputs: signals that select which operation should be performed
- Output lines: the result of the selected operation
- Status outputs: flags such as carry, zero, negative, and overflow
An ALU usually contains two main parts:
Arithmetic section
- : used for operations like addition, subtraction, increment, decrement, and sometimes multiplication/division support in advanced systems.
Logic section
- : used for bitwise operations such as AND, OR, XOR, NOR, and NOT.
Example
If the ALU receives:
- Input A =
1010 - Input B =
0101 - Control signal = ADD
Then the ALU computes:
1010 + 0101 = 1111
If the control signal changes to AND, then:
1010 AND 0101 = 0000
This shows that the same hardware can perform different operations depending on control signals.
ASCII Diagram
Input A -----------\
\
>----[ ALU ]----> Result
/
Input B -----------/
Control Signals -------------------------> Operation Select
Status Flags <--------------------------- Carry, Zero, Overflow
The ALU is a central part of a processor because every calculation, comparison, and many decision-making tasks depend on it.
2. Arithmetic and Logic Operations Performed by ALU
Arithmetic operations
- are mathematical operations carried out on binary numbers.
Logic operations
- work on individual bits and are used for decision-making and bit manipulation.
Arithmetic Operations
Common arithmetic functions include:
Addition
Subtraction
Increment
Decrement
Two’s complement operations
Example of addition:
0110 + 0011 = 1001
Example of subtraction:
Subtraction is often implemented using two’s complement:
- To compute
6 - 3, the ALU adds6 + (-3) - Binary form:
0110 + 1101 = 1 0011- The final result is
0011with carry ignored in fixed-size arithmetic
Logic Operations
Common logic functions include:
AND
- : 1 only if both bits are 1
OR
- : 1 if any bit is 1
NOT
- : inverts the bit
XOR
- : 1 if bits are different
NOR/NAND
- : universal logic operations used in circuit design
Example:
For A = 1100 and B = 1010
- AND =
1000 - OR =
1110 - XOR =
0110
These logic functions are useful in masking, checking conditions, and manipulating individual bits.
Importance in digital systems
- Arithmetic is needed for calculations in programs, scientific computing, and address calculations.
- Logic operations are needed for comparisons, control decisions, and data processing.
3. Control Signals, Status Flags, and ALU Organization
- Control signals determine which operation the ALU performs.
- Status flags indicate the condition of the result after the operation.
- The ALU is usually organized to support multiple operations using multiplexers and subcircuits.
Control Signals
A control unit sends signals to the ALU to specify:
- add
- subtract
- AND
- OR
- compare
- shift
These signals act like instructions telling the ALU what to do.
Status Flags
Typical flags include:
Carry flag (C)
- : set when there is a carry out of the most significant bit
Zero flag (Z)
- : set when the result is zero
Negative flag (N)
- : indicates the sign bit of the result in signed arithmetic
Overflow flag (V)
- : set when signed arithmetic exceeds the representable range
Example
If 1111 + 0001 = 1 0000, the result is 0000 with a carry out.
- Carry flag = 1
- Zero flag = 1
If signed addition produces an invalid range result, overflow is set.
Organization of ALU
An ALU may be built using:
Half adders and full adders
- for addition
Logic gates
- for bitwise operations
Multiplexers
- to choose the correct output
XOR gates
- for subtraction using two’s complement method
A simplified view:
A ----->| |
B ----->| Arithmetic |----\
| Circuit | \
A ----->| | >---[ MUX ]----> Output
B ----->| Logic Circuit | /
| |----/
Control -----------------------> Selects operation
This organization allows one ALU to perform many functions efficiently.
Working / Process
- The ALU receives binary operands from registers or memory and also receives control signals from the control unit.
- Based on the control signals, the ALU selects the required circuit path for arithmetic or logic operation.
- The selected operation is performed, the result is sent to the output register, and status flags are updated for use by the CPU.
Advantages / Applications
- It enables the CPU to perform fast arithmetic and logical processing in hardware.
- It supports a wide variety of operations using the same circuit, making processors compact and efficient.
- It is used in almost every digital system, including microprocessors, calculators, embedded systems, and controllers.
Summary
- ALU is the part of the CPU that performs arithmetic and logic operations on binary data.
- It works as a combinational circuit, so its output depends only on present inputs and control signals.
- It is essential for computation, comparison, and decision-making in digital systems.
- Important terms to remember: ALU, combinational logic, arithmetic operations, logic operations, control signals, status flags