ALU 101 study materials
ALU 101 study resources

ALU 101 common mistakes

ALU 101 · Understand the traps and how to avoid them.

Mistake 1

When subtracting a larger unsigned number from a smaller one, writes the result as the plain magnitude with no indication that it wrapped, instead of reporting the result modulo 2^n together with a borrow/underflow flag.

Treats subtraction as ordinary integer arithmetic learned in school, where a smaller minus a larger number is a negative value; in fixed-width n-bit unsigned arithmetic the result is the low n bits of the true difference and the borrow flag records that the true result was negative.

What to do instead

For every unsigned subtraction, compute the true difference first, then reduce it modulo 2^n and set borrow = 1 when the true difference is negative. State the result as an n-bit pattern plus the flag, never as a signed magnitude.

Mistake 2

Declares two's-complement overflow whenever the carry-out of the most significant bit is 1, or whenever the operands have different signs.

Confuses the carry-out (an unsigned concept tied to the n+1 bit position) with signed overflow, which depends only on the signs of the operands and the result; the two coincide only in special cases.

What to do instead

Apply the signed rule: overflow occurs iff both operands have the same sign and the result's sign differs from theirs. Equivalently, overflow = carry into the sign bit XOR carry out of the sign bit. Use carry-out alone only for unsigned overflow.

Mistake 3

Converts a negative decimal number to two's complement by flipping the sign bit of its positive representation, or by inverting the bits without adding 1.

The sign-magnitude and ones'-complement formats look like simpler ways to encode negatives, so candidates shortcut to them; the add-1 step of two's complement is easy to drop under time pressure.

What to do instead

Use the fixed recipe: write the magnitude in n bits, invert every bit, add 1, and discard any carry beyond n bits. Verify by adding the result to the positive form and confirming the sum is all zeros with the final carry discarded.

Mistake 4

Mixes signed and unsigned interpretations within one comparison or branch, e.g. using a signed less-than after an unsigned subtraction, or reading the sign flag as if it meant 'a < b'.

Flags are computed once by the ALU and then reused by different instructions; candidates assume the sign flag or a single 'negative' result directly answers a less-than question regardless of signedness.

What to do instead

Decide the signedness of the operands before choosing the condition. For signed comparison use sign XOR overflow; for unsigned use the borrow/carry flag. Never infer ordering from the sign flag alone.

Mistake 5

Assumes an arithmetic right shift and a logical right shift produce the same result for negative operands, or that a left shift by k is always safe.

Learns shifts as 'move bits and fill with zeros' and generalises that to all shift types; the sign-extending fill of an arithmetic shift and the bits lost off the top of a left shift are not visually obvious.

What to do instead

State the fill rule explicitly: logical right shift fills with 0, arithmetic right shift replicates the sign bit. For left shifts, check whether any 1 bit is shifted past the width, since that changes the value (and may set an overflow flag).

Mistake 6

Applies De Morgan's law by negating the terms but leaving the operator unchanged, e.g. writing NOT(A AND B) = NOT A AND NOT B.

The negation feels like it distributes over everything, and the operator swap is the one step that is easy to overlook; the two sides look similar at a glance.

What to do instead

Always swap the operator as well as negate each literal: NOT(A AND B) = NOT A OR NOT B, and NOT(A OR B) = NOT A AND NOT B. Sanity-check with one assignment where the operands differ.

Mistake 7

Simplifies a Boolean expression using a rule that is not a valid identity, such as absorbing A + A·B into A·B, or cancelling a term that appears on both sides of an OR.

Pattern-matches to algebraic cancellation from ordinary arithmetic, where x + xy is not x and terms can be divided out; Boolean algebra has no subtraction, so cancellation is invalid.

What to do instead

Derive each step from a named identity (idempotence, absorption A + A·B = A, distributivity, De Morgan). Verify the final expression against the original with a truth table or by testing every combination for small variable counts.

Mistake 8

Describes a sequential circuit's output from its current inputs alone, ignoring the stored state, or treats a latch and a flip-flop as interchangeable.

Carries over combinational intuition, where output is a pure function of inputs; the role of feedback and the edge-versus-level triggering distinction are abstract and easily glossed over.

What to do instead

For any circuit with feedback or memory elements, write the next-state equation and the output equation separately, and evaluate output as a function of (current state, inputs). State explicitly whether the element is level-sensitive (latch) or edge-triggered (flip-flop).

Mistake 9

Computes a multi-bit addition by adding bit columns left to right, or by propagating carries without regard to the order in which the adder produces them.

Habitual left-to-right reading of numbers conflicts with the right-to-left carry chain; ripple-carry adders must resolve each column before the next higher column is final.

What to do instead

Add from the least significant bit upward, carrying into the next column. When reasoning about hardware, note that a ripple-carry adder's worst-case delay grows with the number of bits, which is why carry-lookahead exists.

Mistake 10

Treats the program counter and the instruction register as interchangeable, or claims the ALU writes its result directly into a general-purpose register without going through a destination selected by control.

Both registers hold instruction-related values and both sit near the control logic, so their roles blur; the datapath's write-back path and register-file addressing are easy to skip when tracing an instruction.

What to do instead

Trace one instruction end to end and label each element: PC supplies the address, memory returns the instruction into the IR, control decodes IR fields, the ALU computes, and the result is written to the register file at the destination index on the write-enable signal. Keep PC (address of next instruction) and IR (current instruction) distinct.