CircuitNote

Quick electronics calculators for lab work and circuit design. Free, no sign-up, works in your browser.

한국어

Values accept SI prefixes. Examples: 4.7k 4k7 100n 10u 20mA 1M

ALU

4-Bit ALU Simulator (Arithmetic and Logic)

Choose a function with s1, s0 and Cin, as in a digital logic lab ALU, and get the 4-bit output F and carry Cout. Handy for checking your lab results table.

What the circuit does

The arithmetic unit feeds the adder with Y = s0·B + s1·B̅ and computes F = A + Y + Cin. For s1 s0 = 00, 01, 10, 11 the value of Y is 0000, B, B̅ and 1111, so one adder performs increment, add, subtract (A + B̅ + 1) and decrement. The logic unit is a multiplexer that picks OR, XOR, AND or NOT with s1 s0.

Worked example: subtraction 2 − 1

  1. With s1 s0 = 1 0, Y = B̅ = 1110
  2. F = A + Y + Cin = 0010 + 1110 + 1 = 1 0001 (17)
  3. The fifth bit becomes Cout → F = 0001, Cout = 1, so 2 − 1 = 1 (in subtraction, Cout = 1 means no borrow)

Arithmetic function table

s1 s0 CinOperationFCout
0 0 0Transfer (F = A)00100
0 0 1Increment (F = A + 1)00110
0 1 0Add (F = A + B)00110
0 1 1Add with carry (F = A + B + 1)01000
1 0 0A + B̅ (F = A + B̅)00001
1 0 1Subtract (F = A − B)00011
1 1 0Decrement (F = A − 1)00011
1 1 1Transfer (F = A)00101

Results for A = 0010 (2) and B = 0001 (1). They match measurements on a breadboard 4-bit ALU.

Logic function table

s1 s0OperationF (A = 1100, B = 1010)
0 0OR (F = A ∨ B)1110
0 1XOR (F = A ⊕ B)0110
1 0AND (F = A ∧ B)1000
1 1NOT (F = A̅)0011

Frequently asked questions

How does an ALU subtract with an adder?

It adds the two's complement: A − B = A + B̅ + 1. The arithmetic unit inverts B (s1 s0 = 10) and sets Cin = 1, so the same adder performs subtraction.

Why is Cout 1 after a subtraction?

When A ≥ B, adding A + B̅ + 1 overflows past 4 bits, so Cout = 1 means no borrow was needed. Cout = 0 after a subtraction means the result went negative.