Master the fundamental concepts of cpu design 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 worksMemory-mapped I/O maps device registers into the same address space as RAM. A store to address 0xFF00 might print a character instead of writing DRAM. Embedded ARM and AVR firmware uses this model exclusively.
cLoading…
The CPU does not need new opcodes. Existing LOAD/STORE instructions target either RAM or a device based on address decoding in the memory subsystem.
0x0000 - 0x7FFF0x8000 and above (example map)For example, storing ASCII 72 ('H') to the print port should emit a character on the host console.
For this exercise, you will map one output address to printf or equivalent. This task asks you to extend mem_write with a device hook, the same pattern Linux uses when drivers map PCI BARs into virtual memory.
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.
Implement a CPU's memory-mapped I/O bus. The CPU only knows loads and stores. An address decoder decides whether each access goes to RAM or to a device register, such as a UART that transmits a character when you write to it or a status register that reports whether it's ready. Simulate the bus cycle by cycle, including the classic bug of writing to a busy UART.
| Address | Device | Read | Write |
|---|---|---|---|
0x0000: 0x00FF | RAM (256 bytes, initially 0) | stored byte | store byte |
0xF000 | UART TX data | bus error (write-only) | transmit the byte if ready, else drop it |
0xF001 | UART status | bit 0 = TX ready | bus error (read-only) |
0xF010 | LEDs (8 bits, initially 0) | current value | set value |
| anything else | - | bus error (unmapped) | bus error (unmapped) |
The UART is busy for the 2 cycles after it accepts a byte: a byte accepted in cycle t makes it busy during cycles t+1 and t+2. It is ready again from t+3.
cLoading…
Numbers are decimal or 0x hex. Cycles are numbered from 1.
One line per access:
cLoading…
(the write form uses the same bus-error messages). Addresses print as 4 upper-case hex digits, values as 2. At the end:
cLoading…
Input:
cLoading…
Output:
cLoading…
bus_read(addr) / bus_write(addr, value) pair that decodes the address and dispatches to RAM or a device handler.Hidden tests cover polling the status register until ready, reads of the write-only TX register and writes to the read-only status register, unmapped addresses, the LEDs, and non-printable bytes such as a newline.