- Assembly 76.9%
- Python 17.3%
- Just 5.8%
|
|
||
|---|---|---|
| .asm-lsp.toml | Improve tooling | |
| .gitignore | Improve tooling | |
| asm-calc.s | Add support for negative input numbers | |
| fuzz.py | Add support for negative input numbers | |
| justfile | Add support for negative input numbers | |
| LICENSE | Add LICENSE and README.md | |
| README.md | Add support for negative input numbers | |
asm-calc
This is a really simple calculator for the command line. It's special because it's written in 64-bit RISC-V Assembly.
Compilation
We use the just command runner and the Zig compiler to compile this project.
If you aren't developing directly on a RISC-V machine, you will need to install QEMU on your system.
An executable called qemu-riscv64 should be exposed.
Once you have those installed, simply run the following command to produce a binary called asm-calc:
just build
While debugging, simply run just to also test the program on a few inputs.
Usage
Just pass the calculation you want to perform as a string.
./asm-calc "1+1"
You can pass multiple arguments, and it will calculate each of them.
./asm-calc "15-17" "14*20" "21/3" "10%4"
Both numbers involved in the operation must be signed 64-bit integers.
Operations supported are + (addition), - (subtraction), * (multiplication), / (division) and % (remainder),
as well as & (bitwise AND), | (bitwise OR) and ^ (bitwise XOR).
The result is always a 64-bit signed integer. In the case of division, the result is always rounded towards zero.
Credits
The RISC-V Assembler Cheat Sheet was a great help throughout this project's development.
License
This project is licensed permissively under the MIT License.