C7 Digital logic · Practice
The arithmetic logic unit
Problems dealt one at a time, with new numbers every time. The kinds you miss come back more often, and you can keep going as long as you like.
0 solved
0 in a row
0 of 6 kinds solid
Check
A 4-bit ALU computes A − B for A = 0101 and B = 0001. What 4-bit result does it produce?
Check
A 4-bit ALU subtracts B = 0001 from A = 1010. Signed, A is negative and B positive. What result does it produce? (The V flag will say whether it's wrong.)
Check
A 16-bit ripple ALU has gates of 10 ps: two gate delays per bit of carry, two for the output multiplexer, then a zero detector built as a tree of 2-input gates. How long until Z is valid?
Write units the way you normally would: 1.5 ps and 0.0015 ns are the same answer.
Check
Write alu(a, b, op) for an n-bit ALU (16 bits), with op one of 'and', 'or', 'add', 'sub', taking unsigned inputs below and returning (r, z, neg, c, v): the result and the four flags as 0 or 1, computed the way hardware does (subtract as ; C is the carry out of the top bit; V from the carries into and out of the top bit; logic operations clear C and V). Then write signed_lt(a, b) and unsigned_lt(a, b) using only the flags from alu(a, b, 'sub').
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A 4-bit ALU adds 0101 and 0001. What result does it produce?
Check
How many levels of 4-input gates does a tree need to combine 32 bits into one zero flag?
A kind of problem counts as solid once you've got it right on the first try twice in a row. Back to the lesson · Practice every topic in C7