This is a Soft Processing Unit application with custom assembly language, implementing it's assembler, disassembler and interpreter.
(for full stack debug capabilities add FULL_DEBUG
macro)
$ mkdir build
$ cd build
$ cmake .. -DCMAKE_BUILD_TYPE=Release
$ make
assembler -a [-ho] [filename] < program.gasm [> program.gbin]
Assembles source code in castom assembly to binary file tha could be interpreted
assembler -d [-ho] [filename] < program.gasm [> program.gbin]
Disassembles binary file to human-readable format (assembly language)
interpreter < program.gbin
Interprets binary file and outputs results to stdout
Opcodes could be easily added and modified in ./include/commands.tpl
Opcode | Description | argc |
---|---|---|
idle | Do nothing, could take one argument to create lable indent | 0/1 |
push | Push argument to stack | 1 |
pop | Pop from stack and discard the result / save result to argument | 0/1 |
add | Pop two values from stack, add them and push the result | 0 |
add | Add the second argumen to the first one | 2 |
sub | Pop two values from stack, subtracted them and push the result [push(pop_2 - pop_1)] | 0 |
sub | Subtract the second argumen from the first one | 2 |
mul | Pop two values from stack, multiply them and push the result | 0 |
mul | Multiply the first argument by the second one | 2 |
div | Pop two values from stack, divides them and push the result [push(pop_2 / pop_1)] | 0 |
div | Divides the first argument by the second one | 2 |
mov | Copies value from the second argument to the first one | 2 |
out | Pops value from stack and prints it to stdout |
0 |
out | Prints argument to stdout |
1 |
jmp | Jumps to position of the argument (usually a goto lable) | 1 |
call | Makes a function call by starting position (usually a goto lable) | 1 |
ret | Returns to the position after last call (is stored in general stack) |
0 |
exit | Stop the program interpretation with exit code 0 | 0 |
cmp | Pop two values from stack, compares them and sets comp register [pop_2 cmp pop_1] | 0 |
cmp | Compares arguments and sets comp register | 2 |
jeq | Jumps to position of the argument (usually a goto lable) if comp register is set to equal (0) | 1 |
jl | Jumps to position of the argument (usually a goto lable) if comp register is set to less (-1) | 1 |
jle | Jumps to position of the argument (usually a goto lable) if comp register is set to less or equal (-1 / 0) | 1 |
jg | Jumps to position of the argument (usually a goto lable) if comp register is set to greater (1) | 1 |
jge | Jumps to position of the argument (usually a goto lable) if comp register is set to greater or equal (0 / 1) | 1 |
dec | Decreases the top stack element or the argument | 0/1 |
inc | Increases the top stack element or the argument | 0/1 |
sqrt | Calculates sqrt of the top stack element or the argument | 0/1 |
- Bacis assembly logic (assembler/disassembler/interpreter)
- Optimised bytecode conversion and interpretation
- Basic cli apps and interface (via getopt)
- Recursive operand parsing
- Flexible opcode operands, could implement complex calculations, RAM and register calls
- Limited substraction in operands calculations (better use brackets after substraction, no unary minus, use 0-n)
- GoTo functionality, lables and jumps
- Function calls, no real recursion limit
call main
opening is added to every binary- Lables could be used as vars stored in RAM (check out examples)
- Example programs (solver of quadric equasions and fibinacci recursive calc)
- Easy opcode list extension and modification with preprocessor codegen
- Screaming Capybara ASCII art
- CMake config with fetching my Unkillable Stack ang GoogleTest lib
- Doxygen docs
- Add unit testing and Github Action CI
- Add video-RAM and draw some circles
- Status stack for advanced error handling
- More durable parser and full subtraction support in operands calculations