Wasteland 2 - 6502 Assembler

Assembler modified from http://www.masswerk.at/6502/assembler.html to meet my personal needs for the Wasteland 2 6502 computer, the Agave ][, to be used with a Ruby script to compile the final binary file.

6502 OpCodes | 6502 Tutorial | 6502 Code Samples | 6502 Emulated Programs

src: listing:
'0x' Format: Raw Format:
object code:



This is is simple 2 pass assembler for the 65xx micro processor.

To get your source code compiled:

  1. Enter your source code in the "src" pane.
  2. Select which format you want the op-code to output.
  3. Click the button "generate code".
  4. Watch the progress in the "listing" pane.
  5. Copy any generated code from the "object code" pane, use in the following Ruby script based on the format:

'0x' Format:
program = [...copied object code...]


Raw Format:
opcode = <<EOS
...copied object code...

program = opcode.split(/\s/).map!{|code| code.to_i(16)}



The assembler supports the following syntax:

Opcodes and Addressing
   Instructions are always 3 letter mnemonics followed by an (optional) operand/address:
   OPC .... implied
  OPC A .... Accumulator
  OPC #BB .... immediate
  OPC HHLL .... absolute
  OPC HHLL,X .... absolute, X-indexed
  OPC HHLL,Y .... absolute, Y-indexed
  OPC *LL .... zeropage
  OPC *LL,X .... zeropage, X-indexed
  OPC *LL,Y .... zeropage, Y-indexed
  OPC (BB,X) .... X-indexed, indirect
  OPC (LL),Y .... indirect, Y-indexed
  OPC (HHLL) .... indirect
  OPC BB .... relative
Where HHLL is a 16 bit word and LL or BB a 8 bit byte, and A is literal "A".
There must not be any white space in any part of an instruction's address.
Number Formats
   $[0-9A-Zaz] .... hex
  %[01] .... binary
  0[0-7] .... octal
  [0-9] .... decimal
  < .... LO-byte portion
  > .... HI-byte portion
Labels and Identifiers
   Identifiers must begin with a letter [A-Z] and contain letters, digits, and the underscore [A-Z0-9_]. Only the first 36 characters are significant.
All identifiers, numbers, opcodes, and pragmas are case insensitive and translated to upper case. Identifiers must not be the same as valid opcodes.
The special identifier "*" refers to the program counter (PC).
  * = $C000 .... Set start address (PC) to C000.
  LABEL1 LDA #4 .... Define LABEL1 with the address of instruction LDA.
         BNE LABEL2 .... Jump to address of label LABEL2.
  STORE = $0800 .... Define STORE with value 0800.
  HERE = * .... Define HERE with current address (PC).
  HERE2 .... Define HERE2 with current address (PC).
         LDA #<VAL1 .... Load LO-byte of VAL1.
   Pragmas start with a dot (.) and must be the only expression in a line:
   .BYTE BB .... Insert 8 bit byte at current address into code.
   .WORD HHLL .... Insert 16 bit word at current address into code.
   .END .... End of source, stop assembly. (optional)
   ; comment .... Any sequence of characters starting with a semicolon till the end of the line are ignored.
White Space
   The assembler does not rely on any special formatting with the following exclusion:
There must be white space between a label and a opcode and the opcode and any operands. Only one instruction per line is permitted.
Code Example
   Src:      Listing:
   *=$c000 LDX #0 Label1 TXA STA $0400,X LDA #1 STA $D800,X INX BNE Label1 RTS .END    * = $C000 C000 LDX #$00 A2 00 C002 LABEL1 TXA 8A C003 STA $0400,X 9D 00 04 C006 LDA #$01 A9 01 C008 STA $D800,X 9D 00 D8 C00B INX E8 C00C BNE LABEL1 D0 F4 C00E RTS 60 C00F .END
'0x' Object Code Format:
   0xA2, 0x00, 0x8A, 0x9D, 0x00, 0x04, 0xA9, 0x01, 0x9D, 0x00, 0xD8, 0xE8, 0xD0, 0xF4, 0x60
Raw Object Code Format:
   A2 00 8A 9D 00 04 A9 01 9D 00 D8 E8 D0 F4 60


This program is provided for free and AS IS, therefore without any warranty;
without even the implied warranty of merchantability or fitness for a particular purpose.