Skip to content

astanx/CPU_simulator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CPU Simulator

A simple CPU emulator written in C that executes a basic instruction set.


Clone the Repository

git clone https://github.com/astanx/CPU_simulator
cd CPU_simulator

Build

make

Run

./cpu_simulator

Input Format

Enter 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 Set

Data Movement

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.

Input / Output

Instruction Description
IN Input a character into ACC.
OUT Output ACC as a character.

Arithmetic Operations

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).

Branching

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.

Control

Instruction Description
END End the program.

Clean Up

To remove compiled files:

make clean

About

Little man computer

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published