Master the fundamental concepts of cpu design through this focused micro-challenge.
Your emulator already fetches and decodes instructions. Now the execute stage must dispatch arithmetic and logic opcodes to an ALU module that reads two register operands and writes back a result plus flags.
rs and rt from the register fileopcoderd; update Z/N/C/V flagscLoading…
Teaching ISAs often pack register indices into the instruction byte. For example, bits 4-3 might select destination, bits 2-1 source A, bits 0 source B.
For this exercise, you will connect decode output to ALU operations for ADD, SUB, AND, OR, and NOT. This task asks you to close the loop from instruction bits to numeric results, the same execute-stage wiring QEMU's interpreter performs for each guest instruction.
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.
Add ALU to CPU emulator with arithmetic and logic operations.
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