https://github.com/eigenraven/rvasm
RISC-V Assembler
https://github.com/eigenraven/rvasm
assembler extensible risc-v riscv rust
Last synced: about 1 year ago
JSON representation
RISC-V Assembler
- Host: GitHub
- URL: https://github.com/eigenraven/rvasm
- Owner: eigenraven
- License: apache-2.0
- Archived: true
- Created: 2019-08-06T19:36:39.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-10-26T15:39:28.000Z (over 2 years ago)
- Last Synced: 2025-03-12T19:43:37.967Z (over 1 year ago)
- Topics: assembler, extensible, risc-v, riscv, rust
- Language: Rust
- Size: 44.9 KB
- Stars: 18
- Watchers: 1
- Forks: 5
- Open Issues: 2
-
Metadata Files:
- Readme: README.MD
- License: LICENSE
Awesome Lists containing this project
README
# A RISC-V assembler
An extensible RISC-V assembler written in Rust.
The goal of this project is to provide a platform for experimentation with the RISC-V architecture by having
an assembler that allows for quick iteration of tiny programs compiled into flat binaries, and of instruction
sets defined in simple to edit [TOML 0.5](https://github.com/toml-lang/toml) files.
## Usage
```
USAGE:
rvasm [FLAGS] [OPTIONS] [--] [input_file]
FLAGS:
-h, --help Prints help information
-b, --binary In addition to writing a file, print the assembly in binary to the terminal
-V, --version Prints version information
-v, --verbose Enable additional output
OPTIONS:
-a, --arch RISC-V variant to assemble for, like RV32IMZamZifencei (finds config files in
standard path) [default: RV32I]
-c, --cfg ... Additional config file paths to parse
-s, --string Input string instead of file, all semicolons are replaced by newlines
-o, --output-file Output (assembled) file path
-f, --format Output file format (only `flat` binary is supported) [default: flat]
ARGS:
Input file path
```
For example, if you have a file `sample1.s`:
```
addi s0, s1, 2+2
```
You can assemble it by using the command `rvasm sample1.s -o sample1.bin`.
This is the equivalent of options: `rvasm sample1.s -o sample1.bin -a RV32I -f flat`
If you'd like to peek into the binary representation of instructions (only 32-bit ILEN supported now),
you can invoke rvasm like this:
```
rvasm -s "addi s0, s1, 2+2" -b
```
Which will produce the following output:
```
Binary assembly:
00000000010001001000010000010011
Warning: no output file specified so none was created.
```
Which displays the 32-bit instructions as 32 binary digits, rightmost one is the LSB and leftmost is MSB.
(Swapped around from the actual little endian byte encoding for readability)
## Defining instruction sets
Create a copy of [cfg/help.toml](cfg/help.toml) and follow the comments to define instruction formats and specific encodings.
You can also take a look at the included RV32I definition in [cfg/rv32i.toml](cfg/rv32i.toml).
## Supported directives
Apart from the instructions defined in the TOML files, the assembler supports a few directives:
* `$` - replaced by current PC value
* `.org ADDRESS` - sets the internal PC value and output file position to `ADDRESS`
* `.equ NAME VAL`/`.define NAME VAL` - defines constants that can be used in expressions instead of integers
* `.label:` - labels starting with a dot are local to the scope of their parent label