https://github.com/khmelnitskiianton/processor
My own processor on C that has stack, RAM, and registers
https://github.com/khmelnitskiianton/processor
cpu-emulator
Last synced: about 2 months ago
JSON representation
My own processor on C that has stack, RAM, and registers
- Host: GitHub
- URL: https://github.com/khmelnitskiianton/processor
- Owner: khmelnitskiianton
- Created: 2023-10-05T19:29:30.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-01-23T12:20:51.000Z (over 2 years ago)
- Last Synced: 2025-12-29T23:00:06.546Z (6 months ago)
- Topics: cpu-emulator
- Language: C++
- Homepage:
- Size: 14 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Processor
Its my simple processor!
It consists of my assembler and my spu and can process many interesting codes!
You can see 3 example programs on my asm:
1. `quadratka.txt` - code of quadratic solver
2. `circle.txt` - code that draw circle in console
3. `factorial.txt` - code of recursive factorial
4. `bad_apple.txt` - code that draws BadApple movie in window with SDL
## Running BadApple ##
Git have an edge of file with 100 MB, thats why you need to generate asm code for BadApple with hands(it costs 122 MB and have 10 million commands!)
1. After installation you need to generate asm code and put it in main:
```c
cd ./bad_apple
make start
make run
```
2. You will have file `bad_apple_asm.txt` in ./bad_apple
3. Change its name to `input_text.txt` and copy to main folder!
4. Then start program with `./processor.bat bad_apple.txt`
*Possible Problems:*
> If running bad apple more than 10 sec - than check in `main_hdr/arrays.h` logs are turn off, turn off and recompile
> Sanitizer of memory after BadApple is OK - it is problem in SDL
> Warnings while compiling from sanitizer
## Table of Contents
- [Installation](#installation)
- [Extra programs](#extra-programs)
- [Using](#using)
- [Options of compiling](#options-of-compiling)
- [Logs](#logs)
## Installation
To start program you need to use CMake and run program
1. Clone repository
2. Compile CMake, write command in main directory in repo
3. Run CMake (compile program), write command in main directory in repo
4. Run program(before you need to create this file)
```c
git clone https://github.com/khmelnitskiianton/Processor.git
cd ./Processor
cmake .
make
./processor.bat
```
## Extra programs
If you want to see BadApple movie, you need to install graphic lib - SDL/SDL2
```c
sudo apt install libsdl2-dev -y
```
## Using
My program took code on my asm from text file.
In processor I have stack, registers(`rax` - `rex`), RAM
> After functions that consist of 1 word, dont write any spaces/comments! (it is feature)\
> In another cases, you can write comments after `;` with any spaces
**Functions:** (in `main_hdr/commands.h`)
*push/pop*
+ `push ` - push number in stack
+ `push ` - push value from register to stack
+ `push + number` - push value from register to stack
+ `push [number]` - push number from RAM with index = number to stack
+ `push []` - push number from RAM with index = value in register to stack
+ `push [ + number]` - push number from RAM with index = (value in register + number) to stack
==============================================
+ `pop ` - push number from stack(last ofc) to register
+ `pop [number]` - push number from stack to RAM with index = number
+ `pop []` - push number from stack to RAM with index = value in register
+ `pop [ + number]` - push number from stack to RAM with index = (value in register + number)
*arifmethic operations*
+ `div` - take 2 numbers from stack and push there division to stack
+ `add` - take 2 numbers from stack and push there sum to stack
+ `mul` - take 2 numbers from stack and push there multipling to stack
+ `sub` - take 2 numbers from stack and push there subtract to stack
+ `sqrt` - take number from stack and push its square to stack
+ `cos` - take number from stack and push its cosinus to stack
+ `sin` - take number from stack and push its sinus to stack
*base operations*
+ `in` - ask to enter from console number
+ `out` - take number from stack and print it to console
+ `outc` - take number from stack and print it char equivalent to console
+ `draw` - printing with SDL
+ `drawf` - printing RAM(actually for drawing circle)
+ `hlt` - end of code!
*labels,jumps and functions*
+ `:` - put label to jump
==============================================
+ `jmp ` - command that jump your position to indicated label
+ `ja ` - takes 2 numbers from stack, compares it, and if (last above last_sec) jump your position to indicated label
+ `jae ` - takes 2 numbers from stack, compares it, and if (last above or equal last_sec) jump your position to indicated label
+ `jb ` - takes 2 numbers from stack, compares it, and if (last below last_sec) jump your position to indicated label
+ `jbe ` - takes 2 numbers from stack, compares it, and if (last below or equal last_sec) jump your position to indicated label
+ `jne ` - takes 2 numbers from stack, compares it, and if (last not equal last_sec) jump your position to indicated label
==============================================
+ `call ` - go to label and do code before `ret` (like function!)
+ `ret` - stopper for call in label use in pair!
## Options of compiling
LISTING_MEMORY
LISTING_ASM
DEBUG_PRINTING
## Logs
For debugging I use `listing.txt` - printing asm
For debugging I use `log.txt` - printing cpu