v6502
The MOS 6502 Virtual Machine and Toolchain Infrastructure
Assembler

Arguments and Usage

usage: as6502 [-STWw] [-F format] [file ...]

Any number of files may be specified and they will all be assembled, individually. To create useful binaries, rather than just object files, either specify flat as the format, or link the binaries with the Linker. If no files are specified, as6502 will assemble from stdin, line-buffered.

Notes

When assembling from stdin, label parsing and dereferencing is not supported. This is because the labels are all determined in advance on a first pass that only cares about instruction size, and then the second pass actually begins converting the assembly to machine code, while dereferencing the labels along the way via the pre-built table.

Design

The assembler makes two passes over the source, and aims to be as efficient as possible, while still exposing powerful access to the assembly process.

  1. Reference calculation; conversion of variable names and labels to addresses. Preallocation of object blobs based on dot-prefixed directives.
  2. (Only pass when assembling from stdin) Population of dot-prefixed lines (e.g. Filling .data blocks, assigning .word values, etc.) Conversion of instructions to machine code.

Debugging

Debug output logging has been added to allow printing of the assembly process, as it happens, the output is column oriented and can be seen below. Comment lines, or lines that contain no code or labels, are not printed. The column headers have been added for clarity, and the middle 170 lines omitted for brevity.

Offset Op Lo Hi Line Label / Instruction
------ -- -- -- ---- -------------------
0x0000: 20 03 00 - 15: jsr $0003
0x0003: 20 38 00 - 16: jsr $0038
0x0006: - 18: init:
0x0006: 20 04 00 - 19: jsr $0004
0x0009: 20 1e 00 - 20: jsr $001e
0x000c: 60 - 21: rts
… 170 lines ommitted …
0x0130: a2 00 - 241: ldx #0
0x0132: - 230: drawSnake:
0x0132: ea - 243: nop
0x0133: ea - 244: nop
0x0134: ca - 245: dex
0x0135: d0 0c - 246: bne $0c
0x0137: 60 - 247: rts