Interpreters/Compilers > vas
A simple x86-64 assembler written in V.
vas - x86-64 Assembler written in V
Installation
Docker setup
# Build the Docker image
docker build ./ -t vas
# Run the container
# Linux/MacOS:
docker run --rm -it -v "$(pwd)":/root/env vas
# Windows (CMD):
docker run --rm -it -v "%cd%":/root/env vas
# Windows (PowerShell):
docker run --rm -it -v "${pwd}:/root/env" vas
Build
Requires the V compiler to be installed.
v . -prod
Usage
Basic usage:
vas [options] <input_file>.s
Options:
-o <filename>: Set output file name (default: input_file.o)--keep-locals: Keep local symbols (e.g., those starting with.L)
Example
- Create an assembly file (hello.s):
# Hello world example
.global _start
.section .data, "aw"
msg:
.string "Hello, world!\n"
.section .text, "ax"
_start:
pushq %rbp
movq %rsp, %rbp
subq $16, %rsp
movq $1, %rax # write syscall
movq $1, %rdi # stdout
movq $msg, %rsi # message
movq $14, %rdx # length
syscall
movq $60, %rax # exit syscall
movq $0, %rdi # status code 0
syscall
- Assemble the file:
vas hello.s
- Link the object file:
ld hello.o
- Run the executable:
./a.out
Output:
Hello, world!
Testing
Regression tests live in tests/cases/ as <name>.s (assembly source) +
<name>.expected.md5 (expected MD5 of the assembled .o) pairs. The
runner is a V _test.v file:
v test tests/
This rebuilds vas, runs every case through it, and asserts the output
bytes match the recorded MD5. To add a case:
# 1. drop a new .s file
$EDITOR tests/cases/my_feature.s
# 2. record its expected output
v . # ensure vas is fresh
./vas tests/cases/my_feature.s
md5 -q tests/cases/my_feature.o > tests/cases/my_feature.expected.md5
rm tests/cases/my_feature.o # keep the dir clean
# 3. verify the new case is picked up
v test tests/
Instruction table
The assembler's instruction set is data-driven: rows are generated from
NASM's third_party/insns.dat by tools/gen_insns.v and committed to
encoder/insns_table.gen.v. Regenerate after editing the parser:
v run tools/gen_insns.v
See LICENSE-NASM for the BSD-2-clause notice covering the bundled
insns.dat and the rows derived from it.
Star History
License
This project is licensed under the MIT License - see the LICENSE file for details.