Master the fundamental concepts of cpu design through this focused micro-challenge.
A stack is a LIFO region of RAM accessed via a dedicated stack pointer (SP). PUSH decrements SP (on descending stacks) and stores a value; POP loads the value and increments SP. x86, ARM, and RISC-V all rely on stacks for function calls and local variables.
cLoading…
For example, pushing 0x42 then popping should return 0x42 and restore SP to its pre-push value.
For this exercise, you will add PUSH and POP opcodes that manipulate SP and memory. This task asks you to prepare the call stack that CALL/RET and subroutine local variables depend on in the next exercise.
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 stack with PUSH and POP instructions.
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