Master the fundamental concepts of digital logic & boolean algebra through this focused micro-challenge.
You have read the whole brief, and the concepts above stay free on every task. Writing and running the code needs a plan.
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
Every task includes starter code, theory, and hidden tests so you can implement and verify locally in the browser.
How it worksA 4-bit register is four D flip-flops sharing one clock and one write-enable. On each rising edge, when EN=1, all four D inputs copy into Q outputs simultaneously. When EN=0, the register holds its value.
cLoading…
Registers are the fastest storage a CPU touches: reading R3 in your toy emulator should be a single-cycle operation, unlike RAM.
Four bits can hold values 0 through 15. That is enough for a nibble of BCD, a counter in an embedded timer, or the program counter in a minimal teaching CPU.
For this exercise, you will stitch four D flip-flops into one loadable register and verify parallel writes. This task asks you to treat the register as the bridge between combinational logic (adders, MUXes) and sequential state machines in the hardware simulator ahead.
Keep the relevant datasheet, ISA manual, or architecture textbook chapter open while you implement. When your output disagrees with the reference trace on the same program, the bug is usually a mis-decoded opcode, a stale register read, or a flag bit left unchanged after arithmetic.
For this exercise, you will use those habits while implementing the requirement in the starter code. Microarchitectural product names change across CPU generations, but the control ideas (fetch, bypass, cache lines, vector lanes) stay stable enough to debug from first principles.
Build a 4-bit register from four D flip-flops. A write-enable signal decides whether the register loads new data on the next rising clock edge or keeps its value. Hardware can't "skip" a clock edge, so write-enable is implemented with a 2-to-1 mux in front of each flip-flop that feeds back the current value when WE = 0. An asynchronous clear resets the register immediately, without waiting for the clock.
For each bit i (0..3):
cLoading…
All bits start at 0, and the clock starts at 0.
One signal update per line:
CLK WE DDDD: the new clock level (0/1), write enable (0/1) and 4 data bits (most significant first).clr: asynchronous clear: Q = 0000 immediately. The clock level is unchanged.Number the lines from t=1 (errors are numbered too):
cLoading…
mux is the value of the four mux outputs, computed from the register contents before this line. EVENT is load on a rising edge with WE=1, hold on a rising edge with WE=0, and - when there is no rising edge. A line is bad unless it is clr or three fields: a 0/1, a 0/1 and exactly four 0/1 characters.
Input:
cLoading…
Output:
cLoading…
clr must not depend on the clock.Hidden tests cover the clock held high while data changes (no new edge), clr in the middle of a sequence, and malformed lines.