A C++ program that simulates a basic CPU with registers, memory and simple instructions (load, add, sub, store, print).
Every electronic device runs on a CPU. Understanding how a processor executes instructions at the lowest level is core knowledge for Computer Architecture β a subject every Electrical Engineering student will encounter in their degree!
- 4 general-purpose registers (R0, R1, R2, R3)
- 16 memory slots (addresses 0β15)
- Supported instructions:
- LOAD β load a value directly into a register
- ADD β add two registers, store result
- SUB β subtract two registers, store result
- STORE β save a register value to memory
- PRINT β display a register's current value
- VIEW β display all registers and memory at once
- Interactive menu-driven interface
- Loops until the CPU is halted
β’ Add MUL (multiply) and DIV (divide) instructions
β’ Add a JUMP instruction for simple loops
β’ Add an assembler β let the user type βADD R0 R1 R2β as text
β’ Simulate a fetch-decode-execute cycle
β’ Add a program counter (PC) register