1
0
Fork
You've already forked asm-calc
0
A little calculator for the CLI written in Assembly.
  • Assembly 76.9%
  • Python 17.3%
  • Just 5.8%
2025年11月21日 13:33:32 +01:00
.asm-lsp.toml Improve tooling 2025年11月20日 17:54:02 +01:00
.gitignore Improve tooling 2025年11月20日 17:54:02 +01:00
asm-calc.s Add support for negative input numbers 2025年11月21日 13:33:32 +01:00
fuzz.py Add support for negative input numbers 2025年11月21日 13:33:32 +01:00
justfile Add support for negative input numbers 2025年11月21日 13:33:32 +01:00
LICENSE Add LICENSE and README.md 2025年11月20日 18:02:37 +01:00
README.md Add support for negative input numbers 2025年11月21日 13:33:32 +01:00

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.