5 releases

Uses old Rust 2015

0.1.4 Nov 15, 2021
0.1.3 Aug 10, 2021
0.1.2 Feb 22, 2016
0.1.1 Feb 16, 2016
0.1.0 Feb 11, 2016

#26 in Emulators

21 downloads per month
Used in ya6502

Apache-2.0/MIT

56KB
1K SLoC

A 6502 assembler as a Rust macro Build Status

If you want to lose a bit of your sanity, then this crate is for you!

(no but seriously, you want to use a macro to assemble stuff?)

Documentation

Implemented Features

  • Full compile-time assembly to executable machine code
  • Machine code is emitted as a constant u8 array (you can store it in a static or const)
  • Label support (loop: jmp loop, beq start)
  • Supports all official 6502 opcodes and addressing modes

lib.rs:

A MOS6502 assembler implemented as a macro.

Note: Due to limitations in Rust macros, there are two deviations from a typical 6502 assembly syntax:

  • For absolute addressing mode, you need to use abs after the mnemonic (eg. lda abs 0xffff).
  • For accumulator addressing mode, you need to use a after the mnemonic (eg. lsr a).

Example

#[macro_use] #[no_link]
extern crate rustasm6502;

fn main() {
    let machine_code = assemble6502! {
        lda #0x00
        ldx #0x00
        ldy #0x00
        txs

    main:
        adc 0xff        // Zero-Page
        adc abs 0x1234  // Absolute address 0x1234
        ror a           // Rotate the accumulator
        beq main
    end:
        jmp end
    };

    assert_eq!(machine_code, [
        0xA9, 0x00,
        0xA2, 0x00,
        0xA0, 0x00,
        0x9A,

        0x65, 0xff,
        0x6D, 0x34, 0x12,   // Little-endian
        0x6A,
        0xF0, (-8i8) as u8,

        0x4C, 15, 0,
    ]);
}

No runtime deps