Website Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
3 files changed, 175 insertions, 73 deletions
-rw-r--r--README.md106
-rw-r--r--assembler/README.md88
-rw-r--r--vm/README.md54
diff --git a/README.md b/README.md
index b73ef0a..89b9cf6 100644
--- a/README.md
+++ b/README.md
@@ -1,93 +1,53 @@
# tonkobali
+Rust project for the [Programming with Rust](https://2024.fmi.rust-lang.bg/) elective at FMI.
+This is a small [SUBLEQ](https://en.wikipedia.org/wiki/One-instruction_set_computer#Subtract_and_branch_if_less_than_or_equal_to_zero)-based virtual machine and assembler for it.
+More information can be found in the READMEs of the appropriate crates.
+Some example programs are provided in `examples`.
-## Getting started
-
-To make it easy for you to get started with GitLab, here's a list of recommended next steps.
-
-Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
-
-## Add your files
+## Usage
-- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
-- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
+Install `cargo` on your system.
+For Nix-capable machines you may get an environment with everything you need with:
+```sh
+nix develop
```
-cd existing_repo
-git remote add origin https://gitlab.com/Syndamia/tonkobali.git
-git branch -M main
-git push -uf origin main
-```
-
-## Integrate with your tools
-- [ ] [Set up project integrations](https://gitlab.com/Syndamia/tonkobali/-/settings/integrations)
+To assemble and then execute the `math.s` program just execute:
-## Collaborate with your team
-
-- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
-- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
-- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
-- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
-- [ ] [Set auto-merge](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
-
-## Test and Deploy
-
-Use the built-in continuous integration in GitLab.
+```sh
+cargo run --bin assembler -- ./examples/math.s
+cargo run --bin vm -- ./program.bin
+```
-- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
-- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
-- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
-- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
-- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
+Wait until you see a prompt with `HALTED` with red background to the left of your cursor.
+You're now in the interface of the virtual machine.
-***
+Then enter `1000.1001`, you should get the following output:
-# Editing this README
+```
+1000: 55 1
+```
-When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template.
+To exit the vm enter `quit`.
-## Suggestions for a good README
+## Resources
-Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
+- [Wikipedia on SUBLEQ](https://en.wikipedia.org/wiki/One-instruction_set_computer#Subtract_and_branch_if_less_than_or_equal_to_zero)
+- [masswerk's 6502 instruction set](https://www.masswerk.at/6502/6502_instruction_set.html#AND)
+- [rmac's source format](https://rmac.is-slick.com/manual/manual/#source-format)
+- [sbprojects on wozmon](https://www.sbprojects.net/projects/apple1/wozmon.php)
## Name
-Choose a self-explaining name for your project.
-
-## Description
-Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
-
-## Badges
-On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
-
-## Visuals
-Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
-
-## Installation
-Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
-
-## Usage
-Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
-
-## Support
-Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
-
-## Roadmap
-If you have ideas for releases in the future, it is a good idea to list them in the README.
-
-## Contributing
-State if you are open to contributions and what your requirements are for accepting them.
-
-For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
-
-You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
-## Authors and acknowledgment
-Show your appreciation to those who have contributed to the project.
+The name of this project has some logic behind it.
-## License
-For open source projects, say how it is licensed.
+"SUBLEQ" can be shortened to "SL".
+"SL" also stands for [Sierra Leone](https://en.wikipedia.org/wiki/Sierra_Leone), a small african country.
+Sierra Leone is divided into [16 districts](https://en.wikipedia.org/wiki/Districts_of_Sierra_Leone), the two center-most being "Tonkolili" and "Bombali".
-## Project status
-If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
+Therefore, "tonkobali" represents the composition of the two central components inside SL.
+Before, the vm crate was called "tonkolili" and assembler - "bombali".
+These names were dropped because they were confusing.
diff --git a/assembler/README.md b/assembler/README.md
new file mode 100644
index 0000000..0b148e5
--- /dev/null
+++ b/assembler/README.md
@@ -0,0 +1,88 @@
+# tonkobali assembler
+
+This is a very limited assembler.
+Since we support only a single instruction (SUBLEQ), the assembler can also take in "higher-level" instructions which are then simplified (an operation which I call in the codebase as "collapse") to SUBLEQ.
+
+The main goal is to use these higher-order instructions, not subleq itself.
+Look at the `examples` directory for examples.
+
+## Text format
+
+There are two types of lines in your source file: instruction calls and variable definitions.
+Blank lines are allowed.
+
+### Instruction calls
+
+```asm
+label: instruction arg1, arg2, ... ; Comment until the end of the line
+```
+
+Labels and comments are optional.
+A label is a name, refer to [names](#names) for allowed characters.
+
+You may separate a label and it's instruction by a newline and blank lines.
+You may issue multiple labels one after another, but **only** when separated by at least one newline (meaning you may not define two labels on the same line).
+
+Instruction must be separated from their first argument with a blank (space or tab).
+Capitalisation is **not** ignored.
+
+Arguments are [values](#values), with minor type limitations in certain higher-order instructions.
+They are seprated by commas with arbitrary amount of blank (space or tab) characters around the commas.
+All arguments must be on the same line as their instruction.
+
+### Variable definitions
+
+```asm
+name = value ; Comment until the end of the line
+```
+
+Comments are optional.
+
+### Names
+
+A name is a sequence of ASCII letters (capital and lowercase), numbers, underscore, dot, $ and ?.
+Capitalization is **not** ignored.
+
+There is no scoping of names, or in other words, every name is global.
+Labels are also names.
+
+Repeat names overwrite previous ones **globally**, meaning no matter where two definitions are, the second will override the first everywhere in your program.
+
+### Values
+
+All values are reduced to addresses in the memory (after all, all SUBLEQ arguments are addresses).
+We distinguish between three "types" of values:
+
+- Absolute addresses, these are addresses in the memory and are passed down as-is
+
+ They are defined as unsigned numbers, prepended with the `%` symbol.
+ For example: `%384`.
+
+- Number constants, they're placed somewhere in memory and their address is passed
+
+ They are signed 64-bit numbers (as is the Word type for our VM).
+ For example: `56`, `-912`.
+
+- Strings, they're converted into a sequence of numbers, each being the decimal ASCII representation of the character, ending with a zero. The address of the first "ltter" is passed
+
+ They are a sequence of characters, surrounded by double quotes.
+ Double quotes and backwards slash can be escaped by prepending a backwards slash.
+ For example: `"Hello World"`, `"He said \"Wow\""`, `"C:\\System"`.
+
+## Higher-order instructions
+
+| Instruction | Description | Argument 1 | Argument 2 |
+| ----------- | ------------------------------------------------------------------------- | ------------------- | ------------------- |
+| jmp | Jump to address | Location to jump to | |
+| inc | Increment value | Location of value | |
+| dec | Decrement value | Location of value | |
+| add | Add the first value to the second and store the result in the second | First value | Second value |
+| sub | Subtract the first value to the second and store the result in the second | First value | Second value |
+| mov | Move (copy) the value from the first address to the second address | First location | Second location |
+| beq | Branch if first value is equal to zero | Value to check | Location to jump to |
+| jsr | Jump to subroutine | Location to jump to | |
+| rts | Return from subroutine | | |
+
+The idea of subroutines is that jumping to one is the same as normal jump, however the address after the jump is stored.
+So, returning from a subroutine allows you to jump back after the location you entered the subroutine from.
+Addresses are stored in the memory via a "stack", in the first 1024 addresses.
diff --git a/vm/README.md b/vm/README.md
new file mode 100644
index 0000000..e488993
--- /dev/null
+++ b/vm/README.md
@@ -0,0 +1,54 @@
+# tonkobali virtual machine
+
+This is a virtual machine which executes SUBLEQ instructions.
+The idea is we have a vector of words (i64) which represents our entire memory.
+We use a certain amount of addresses in the beginning of this memory for our purposes.
+
+Since we have only one instruction we only store data, no opcodes.
+When the virtual machine program counter is at a certain location, the next three values from memory are read and SUBLEQ is executed with those values as arguments.
+This continues until the program jumps to address 0, when we reach a "HALTED" state.
+
+## TUI
+
+Once started, you may enter commands for the VM, and to the left of your cursor you'll see vertical bars.
+If the contents of these bars is empty, it means the machine is executing instructions.
+If the contents are "HALTED", the machine has stopped executing.
+If the contents are "STEP", the VM is in single-step mode.
+
+All commands and their meaning can be found by issuing `help`:
+
+```
+<ADDRESS> is a usize constant
+<VALUE> is a Word (i64) constant
+
+Multiple 'Memory IO' commands may be put on a single line, when
+separated by spaces
+
+General commands:
+ h, ?, help This menu
+ q, e, quit, exit Stop and exit the virtual machine
+
+Normal execution:
+ r, run <ADDRESS> Start normal execution at ADDRESS
+ Only applicable when 'HALTED'
+
+Single-step execution:
+ s, single <ADDRESS> Start single-step execution at ADDRESS
+ c, continue Resume normal execution
+ Only applicable when in 'STEP' mode
+ n, next Execute next instruction
+ Only applicable when in 'STEP' mode
+
+Memory IO:
+ <ADDRESS> Print the value at the location
+ <ADDRESS>.<ADDRESS> Print the values between the locations
+ (inclusive range)
+ <ADDRESS>:<VALUE> Set value at ADDRESS to VALUE
+```
+
+Single-step mode allows you to execute only a single instruction at a time.
+After each execution the arguments to SUBLEQ are printed.
+At any point you may manipulate the memory.
+Then you can execute the next single instruction (with `next`) or resume normal execution (with `continue`).
+
+The memory io commands are inspired from Steve Wozniak's wozmon.