A simple 6502 assembler written in Rust
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tromino d2f86000ce Increment version number to 0.1.1 2 weeks ago
demos/nes-music-driver Add music driver example 2 weeks ago
src Increment version number to 0.1.1 2 weeks ago
.gitignore Set up a basic Rust project 5 months ago
Cargo.lock Get a barebones assembler running 5 months ago
Cargo.toml Increment version number to 0.1.1 2 weeks ago
LICENSE.md Add license 2 weeks ago
README.md Add more documentation to README.md 2 weeks ago



The most awesomest 6502 assembler you've ever seen in your life!

nyasm is a toy 6502 assembler I made in order to learn Rust. It's currently pretty early on and there will probably be breaking changes in the future. Right now it's in a state where it can successfully assemble a valid NES ROM file, although some features might still be incomplete or missing entirely (including external binary files is possible now, but including other assembly files isn't for example).


nyasm can be built using cargo:

$ cargo build --release

The resulting binary will appear at target/release/nyasm.


To assemble a file using nyasm, give the input and output filenames to the nyasm binary like this:

$ nyasm input.asm -o output.nes

You can also pipe data into and out of the assembler without accessing the filesystem directly:

$ nyasm < input.asm > output.nes

See the demos folder for examples of what nyasm can do currently.

Supported Syntax

You can use the label_name: syntax to declare a label:

	jmp my_label

If you want, you can also use the .label directive instead, with no difference in behavior:

.label my_label
	jmp my_label

Comments can be written using a semicolon:

; This is where the magic begins...
	lda #$2a ; 42 in hex!

Directives with multiple parameters have them separated with a comma:

	.addr reset,reset,reset ; Writes the address of the reset label 3 times
	.pad $4000,$2a

Directives with string values should have them wrapped in quotes to preserve casing:

	.incbin "includes/dialog.txt"

Normal instructions and directives are case insensitive:

	.BYTE $01,$23,$AB,$CD

Assembler Directives

Here's a list of the assembler directives that nyasm currently supports:


Places one or more 8-bit values into the assembled binary:

.byte $00,$ff,$00,$ff


Same as .byte, but for 16-bit values:

.addr $0000,$ffff,my_label


An alternative syntax for declaring labels:

.label my_label


Sets the "origin point" for labels, or where the first byte in the assembled file would map to in the CPU's address space:

.org $7ff0 ; The beginning of the NES PRG-ROM minus the 16-byte header


Pads the assembled file with zeros up until the specified address:

.pad $2000

You can also provide a custom byte to pad with by setting the second parameter:

.pad $2000,$2a


Includes the specified file as binary data in the assembled file:

.incbin "music.bin"

All paths given are relative to the currently navigated directory in the terminal emulator.