Aim

To study and simulate the working of a 4-bit Arithmetic Logic Unit (ALU) based on the 74181 IC. The experiment demonstrates how an ALU selects between 16 arithmetic and 16 logic operations using a 4-bit function select input (S3–S0) and a mode control bit (M), and how it produces a 4-bit output along with carry-out.

Theory

What is an ALU?

An Arithmetic Logic Unit (ALU) is a fundamental building block of a CPU. It is a combinational digital circuit that performs arithmetic and bitwise logic operations on integer binary numbers. The ALU is the core component that executes all computations within a processor.

The 74181 ALU IC

The 74181 is a 4-bit ALU integrated circuit that was widely used in early minicomputers and is a standard reference for computer architecture education. It can perform 16 arithmetic operations and 16 logic operations, selected by:

  • S3, S2, S1, S0 — 4 function select lines that choose the specific operation.
  • M (Mode) — Selects between arithmetic mode (M=0) and logic mode (M=1).
  • Cin (Carry In) — Carry input for arithmetic operations (ignored in logic mode).

Architecture of the ALU

The simulator models the following internal structure:

  1. Arithmetic Unit — Performs addition, subtraction, increment, decrement, and compound arithmetic on inputs A and B, influenced by the carry input.
  2. Logic Unit — Performs bitwise operations such as AND, OR, XOR, NAND, NOR, and complement on inputs A and B.
  3. Multiplexer — Controlled by the mode bit M, selects the output from either the Arithmetic Unit or the Logic Unit.

Inputs and Outputs

Signal Width Description
A (A3–A0)4 bitsFirst operand input register
B (B3–B0)4 bitsSecond operand input register
S (S3–S0)4 bitsFunction select lines
M1 bitMode control (1=Logic, 0=Arithmetic)
Cin1 bitCarry input (arithmetic mode only)
F (F3–F0)4 bitsResult output
Cout1 bitCarry output (arithmetic mode only)

Logic Operations (M = 1)

When the mode bit M is HIGH, the ALU performs bitwise logic operations. The carry input is ignored and the carry output is always 0. Examples include:

  • S = 0000 → F = A (Complement of A)
  • S = 0110 → F = A ⊕ B (Exclusive OR)
  • S = 1011 → F = AB (AND)
  • S = 1110 → F = A + B (OR)
  • S = 1111 → F = A (Pass-through)

Arithmetic Operations (M = 0)

When M is LOW, the ALU performs arithmetic operations. Both the carry input and carry output are active. The result depends on both the selection lines and the carry input value.

  • S = 0000, Cin=0 → F = A (Transfer A)
  • S = 0110, Cin=1 → F = A − B (Subtraction)
  • S = 1001, Cin=0 → F = A + B (Addition)
  • S = 1100, Cin=0 → F = A + A (Double A)

Carry and Overflow

Carry Out (Cout): In arithmetic mode, if the result exceeds the 4-bit range (0–15 unsigned), Cout is set to 1, indicating a carry has been generated from the most significant bit.

Overflow: Overflow occurs when the result of an arithmetic operation cannot be represented within the available bit width. For unsigned 4-bit numbers, any result ≥ 16 or < 0 causes an overflow/underflow condition. The carry flag helps detect this.

Advantages of the ALU

  • Combines arithmetic and logic functions in a single unit, reducing hardware complexity.
  • Cascadable — multiple 74181 ICs can be connected for wider data paths (8-bit, 16-bit).
  • Carry look-ahead support for high-speed arithmetic (via 74182 carry look-ahead generator).

Limitations

  • Limited to 4-bit data width per IC.
  • No built-in support for multiplication, division, or floating-point operations.
  • Carry propagation delay increases with cascaded width (unless using look-ahead).

Pretest

Answer the following questions before using the simulator to assess your understanding of ALU concepts.

Question 1
What is the primary function of an ALU in a CPU?
  • a) Store data in registers
  • b) Perform arithmetic and logic operations
  • c) Fetch instructions from memory
  • d) Control the sequence of operations
Answer: b) The ALU performs arithmetic operations (addition, subtraction) and logic operations (AND, OR, XOR, NOT) on binary data.
Question 2
In the 74181 ALU, what does the mode control bit M determine?
  • a) The data width of the operation
  • b) Whether the ALU performs arithmetic or logic operations
  • c) The clock speed of the ALU
  • d) The carry-in value
Answer: b) M = 1 (HIGH) selects logic mode; M = 0 (LOW) selects arithmetic mode.
Question 3
How many total operations can the 74181 ALU perform?
  • a) 16
  • b) 24
  • c) 32
  • d) 64
Answer: c) 16 logic operations + 16 arithmetic operations = 32 total operations.
Question 4
If A = 0101 and B = 0011, what is A XOR B?
  • a) 0001
  • b) 0110
  • c) 0111
  • d) 1001
Answer: b) XOR produces 1 where bits differ: 0⊕0=0, 1⊕0=1, 0⊕1=1, 1⊕1=0 → 0110.
Question 5
What is the carry output when adding A = 1101 and B = 0101 in 4-bit unsigned arithmetic?
  • a) 0
  • b) 1
  • c) Depends on mode
  • d) Not defined
Answer: b) 1101 (13) + 0101 (5) = 10010 (18), which exceeds 4 bits. The 5th bit is the carry out = 1, and the 4-bit result is 0010.
Question 6
In logic mode (M=1), is the carry input (Cin) used?
  • a) Yes, it affects the logic output
  • b) No, it is ignored in logic mode
  • c) Only when S = 0000
  • d) Only for OR operations
Answer: b) In logic mode, the carry input has no effect. The output depends only on A, B, and the select lines S3–S0.
Question 7
What does the 74181 output when S = 1111 and M = 1 (logic mode)?
  • a) F = 0000 (all zeros)
  • b) F = 1111 (all ones)
  • c) F = A
  • d) F = B
Answer: c) S = 1111 in logic mode passes input A directly to the output (identity/transfer operation).
Question 8
What is the purpose of the multiplexer inside the ALU?
  • a) To convert analog signals to digital
  • b) To select the output from either the arithmetic or logic unit based on the mode bit
  • c) To store intermediate results
  • d) To generate the carry look-ahead signal
Answer: b) The multiplexer uses the mode bit M to route either the arithmetic unit's output or the logic unit's output to the final result F.

Procedure

Follow these steps to operate the 4-Bit ALU Simulator:

1
Navigate to the Simulation tab to access the interactive ALU circuit diagram.
2
Set the Mode (M): Click the MODE button to toggle between LOGICAL (M=1) and ARITHMETIC (M=0). In logical mode, the Logic Unit is highlighted; in arithmetic mode, the Arithmetic Unit is highlighted.
3
Set Input A: Click the bit buttons A3, A2, A1, A0 to toggle each bit between 0 and 1. This sets the 4-bit value in Register A.
4
Set Input B: Similarly, click B3, B2, B1, B0 to set the 4-bit value in Register B.
5
Set Select Lines (S3–S0): Click S3, S2, S1, S0 to choose which of the 16 operations to perform. Refer to the Truth Table for the operation corresponding to each selection code.
6
Set Carry In (Cin): In arithmetic mode, click the Cin button to toggle the carry input. This is disabled (dimmed) in logic mode.
7
Observe the Output: The result immediately appears in the output nodes (F3–F0) and Carry Out. The HUD panel on the right shows the current values in decimal and binary, along with the operation being performed.
8
View Truth Tables: Click the "Truth Tables" button in the simulation to open a side panel showing the complete truth table for either Logic or Arithmetic operations (depending on the current mode).

Expected Observations

  • Animated signal paths (dashed pulse lines) show the data flow through the active unit.
  • The active unit (arithmetic or logic) is highlighted while the other is dimmed.
  • In logic mode, Cin and Carry Out are dimmed since they are not relevant.
  • Changing any input instantly recalculates the output — the circuit is combinational (no clock needed).
Arithmetic Unit
Logic Unit
Multiplexer
Reg A
A3
0
A2
0
A1
0
A0
0
Reg B
B3
0
B2
0
B1
0
B0
0
Cin
0
MODE :
LOGICAL
0
S3
0
S2
0
S1
0
S0
Output
Carry
0
F3
0
F2
0
F1
0
F0
0
Current State
A: 0000 (0)
B: 0000 (0)
S: 0000 (0)
Output: 0000 (0)
F = A

ALU Truth Tables

Logic Operations

SelectionLogic (M=H)
S3S2S1S0Output
LLLLA
LLLHA+B
LLHLAB
LLHHLogical 0
LHLLAB
LHLHB
LHHLA ⊕ B
LHHHAB
HLLLA+B
HLLHA ⊕ B
HLHLB
HLHHAB
HHLLLogical 1
HHLHA+B
HHHLA+B
HHHHA

Arithmetic Operations

SelectionActive High Data
M=L; Arithmetic Operations
S3S2S1S0Cn = H (with carry)Cn = L (no carry)
LLLLF=AF=A Plus 1
LLLHF=A+BF=(A+B) Plus 1
LLHLF=A+BF=(A+B) Plus 1
LLHHF=Minus 1(2's Compl)F=Zero
LHLLF=A Plus ABF=A Plus AB Plus 1
LHLHF=(A+B) Plus ABF=(A+B) Plus AB Plus 1
LHHLF=A Minus B Minus 1F=A Minus B
LHHHF=AB Minus 1F=AB
HLLLF=A Plus ABF=A Plus AB Plus 1
HLLHF=A Plus BF=A Plus B Plus 1
HLHLF=(A+B) Plus ABF=(A+B) Plus AB Plus 1
HLHHF=AB Minus 1F=AB
HHLLF=A Plus AF=A Plus A Plus 1
HHLHF=(A+B) Plus AF=(A+B) Plus A Plus 1
HHHLF=(A+B) Plus AF=(A+B) Plus A Plus 1
HHHHF=A Minus 1F=A