Master the fundamental concepts of cpu design through this focused micro-challenge.
CALL saves the return address (current PC) on the stack and jumps to a subroutine. RET pops that address back into PC, resuming the caller. This is how main invokes printf without losing its place.
cLoading…
On entry, callees often save frame pointer and allocate locals:
BP, adjusts SP for localsFor example, if PC=0x100 when CALL executes at 0x50, the stack holds 0x51 (address of the next instruction) and PC jumps to the function entry.
For this exercise, you will extend your stack with CALL and RET opcodes. You will need nested calls working before the pipeline tasks, because mispredicted returns are a classic branch-predictor failure mode in real silicon.
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 CALL and RET instructions for subroutines.
Requirements:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
All starter code and reference implementations are available for your local setup.
View on Github