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:
quadratka.txt
- code of quadratic solvercircle.txt
- code that draw circle in consolefactorial.txt
- code of recursive factorialbad_apple.txt
- code that draws BadApple movie in window with SDL
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!)
- After installation you need to generate asm code and put it in main:
cd ./bad_apple
make start
make run
- You will have file
bad_apple_asm.txt
in ./bad_apple - Change its name to
input_text.txt
and copy to main folder! - 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
To start program you need to use CMake and run program
- Clone repository
- Compile CMake, write command in main directory in repo
- Run CMake (compile program), write command in main directory in repo
- Run program(before you need to create this file)
git clone https://github.com/khmelnitskiianton/Processor.git
cd ./Processor
cmake .
make
./processor.bat <name_of_file_where_read_code>
If you want to see BadApple movie, you need to install graphic lib - SDL/SDL2
sudo apt install libsdl2-dev -y
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 <number>
- push number in stackpush <reg>
- push value from register to stackpush <reg> + number
- push value from register to stackpush [number]
- push number from RAM with index = number to stackpush [<reg>]
- push number from RAM with index = value in register to stackpush [<reg> + number]
- push number from RAM with index = (value in register + number) to stack
==============================================
pop <reg>
- push number from stack(last ofc) to registerpop [number]
- push number from stack to RAM with index = numberpop [<reg>]
- push number from stack to RAM with index = value in registerpop [<reg> + 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 stackadd
- take 2 numbers from stack and push there sum to stackmul
- take 2 numbers from stack and push there multipling to stacksub
- take 2 numbers from stack and push there subtract to stacksqrt
- take number from stack and push its square to stackcos
- take number from stack and push its cosinus to stacksin
- take number from stack and push its sinus to stack
base operations
in
- ask to enter from console numberout
- take number from stack and print it to consoleoutc
- take number from stack and print it char equivalent to consoledraw
- printing with SDLdrawf
- printing RAM(actually for drawing circle)hlt
- end of code!
labels,jumps and functions
<name_of_label>:
- put label to jump
==============================================
jmp <name_of_label>
- command that jump your position to indicated labelja <name_of_label>
- takes 2 numbers from stack, compares it, and if (last above last_sec) jump your position to indicated labeljae <name_of_label>
- takes 2 numbers from stack, compares it, and if (last above or equal last_sec) jump your position to indicated labeljb <name_of_label>
- takes 2 numbers from stack, compares it, and if (last below last_sec) jump your position to indicated labeljbe <name_of_label>
- takes 2 numbers from stack, compares it, and if (last below or equal last_sec) jump your position to indicated labeljne <name_of_label>
- takes 2 numbers from stack, compares it, and if (last not equal last_sec) jump your position to indicated label
==============================================
call <name_of_label>
- go to label and do code beforeret
(like function!)ret
- stopper for call in label use in pair!
LISTING_MEMORY
LISTING_ASM
DEBUG_PRINTING
For debugging I use listing.txt
- printing asm
For debugging I use log.txt
- printing cpu