A simple CPU emulator written in C that executes a basic instruction set.
git clone https://github.com/astanx/CPU_simulator
cd CPU_simulatormake./cpu_simulatorEnter instructions, numbers (prefixed with #), addresses, or registers separated by whitespace.
End the program with the END instruction.
Example:
LDM #5
STO 1
OUT
END
| Instruction | Description |
|---|---|
LDM #n |
Load number n into ACC. |
LDD addr |
Load number from memory address addr into ACC. |
LDI addr |
Load number from the memory address stored at addr (indirect) into ACC. |
LDX addr |
Load number from memory address addr + IX into ACC. |
LDR #n |
Load number n into IX. |
MOV |
Move ACC to IX. |
STO addr |
Store value of ACC into memory address addr. |
| Instruction | Description |
|---|---|
IN |
Input a character into ACC. |
OUT |
Output ACC as a character. |
| Instruction | Description |
|---|---|
ADD #n / addr |
Add number or memory value to ACC. |
SUB #n / addr |
Subtract number or memory value from ACC. |
INC reg |
Increment register (IX or ACC). |
DEC reg |
Decrement register (IX or ACC). |
| Instruction | Description |
|---|---|
JMP addr |
Jump to address addr. |
CMP #n / addr |
Compare ACC with number or memory value. |
CMI addr |
Compare ACC with value at indirect address. |
JPE addr |
Jump to address addr if comparison is true. |
JPN addr |
Jump to address addr if comparison is false. |
| Instruction | Description |
|---|---|
END |
End the program. |
To remove compiled files:
make clean