[ << ] [ >> ]           [] [] [] [ ? ]

26 6502 cpu module

This chapter documents the backend for the MOS/Rockwell 6502 microprocessor family. It also supports the Rockwell/WDC 65C02, the Hudson Soft HuC6280 and the WDC 65802/65816 instruction sets.


26.1 Legal

This module is written in 2002,2006,2008-2012,2014-2024 by Frank Wille and is covered by the vasm copyright without modifications.


26.2 Additional options for this module

This module provides the following additional options:

-6280

Recognize all HuC6280 instructions. Includes setdp $2000, so zero-page addressing modes will be automatically used from $2000 to $20ff.

-802

Same as ‘-816’. There is no difference in the instruction set.

-816

Enables the 8/16 bit instruction set for the WDC65816/65802 and additional directives to switch loading of the accumulator and/or the index register between 8 and 16 bits. The target address size becomes 24 bits.

-am

Automatically mask values to match their data size or the size of immediate addressing, which effectively disables any range checks on immediate and data values in the assembler and linker.

-bbcade

Swap meaning of < and > selectors for compatibility with the BBC ADE assembler.

-c02

Recognize all 65C02 instructions. This excludes DTV (‘-dtv’) and illegal (‘-illegal’) instructions.

-ce02

Enables the Commodore CSG65CE02 instruction set, which extends on the WDC02 instruction set.

-dpo

Generate 8-bit offset instead of absolute relocations when accessing a zero- or direct-page symbol.

-dtv

Recognize the three additional C64-DTV instructions.

-illegal

Allow ’illegal’ 6502 instructions to be recognized.

-mega65

Enables the 45GS02 instruction set for the MEGA65 computer.

-opt-branch

Enables translation of B<cc> branches into sequences of B<!cc> *+5 ; JMP label when necessary. BRA (DTV, 65C02) is directly translated into a JMP when out of range. It also performs optimization of JMP to BRA, whenever possible.

-wdc02

Recognize all 65C02 instructions and the WDC65C02 extensions (RMB,SMB,BBR,BBS,STP,WAI).


26.3 General

This backend accepts 6502 family instructions as described in the instruction set reference manuals from MOS and Rockwell, which are valid for the following CPUs: 6502 - 6518, 6570, 6571, 6702, 7501, 8500, 8502.

Optionally accepts 65C02 family instructions as described in the instruction set reference manuals from Rockwell and WDC. Also supports the WDC extensions in the W65C02 and W65C134.

Optionally accepts 65CE02 family instructions as described in the instruction set reference manuals from Commodore Semiconductor Group.

Optionally accepts HuC6280 instructions as described in the instruction set reference manuals from Hudson Soft.

Optionally accepts 45GS02 instructions as defined by the Mega65 project.

Optionally accepts WDC65816 insructions as described in the Programming Manual by The Western Design Center.

The target address type is 16 bits, or 24 bits in WDC65816 mode.

Instructions consist of one up to three bytes for the standard 6502 family (up to 7 bytes for the 6280) and require no alignment. There is also no alignment requirement for sections and data.

All known mnemonics for illegal instructions are optionally recognized (e.g. dcm and dcp refer to the same instruction). Some illegal insructions (e.g. $ab) are known to show unpredictable behaviour, or do not always work the same on different CPUs.

Note that the WDC65816’s MVN and MVP block move instructions require a full 24-bit address (or a label) for the source and destination, as documented in WDC’s Programming Manual. To specify the bank only, you have to use immediate addressing syntax. Example: mvn #$7f,#^label.


26.4 Extensions

Note that some of these extensions have changed since version 1.0 of this backend. Bitstream-selectors (to get the low-byte, high-byte, etc. of an expression) are no longer available as unary operators, to avoid inconsistencies, and to better conform with classic assemblers and the official WDC syntax.

This backend provides the following specific extensions:

This backend extends the selected syntax module by the following directives:

a8

Declares that immediate instructions accessing the accumulator have 8 bits width (default, WDC65816 only).

a16

Declares that immediate instructions accessing the accumulator have 16 bits width (WDC65816 only).

as

Alias for a8 (WDC65816 only).

al

Alias for a16 (WDC65816 only).

cpu <name>

Define the cpu model. Must be specified before any code is generated and has priority over cpu settings on the command line. Most common names are recognized, like: 65c02, wdc02, 65816, HU6280, 45gs02, 6510, etc.

<symbol> ezp <expr>

Works exactly like the equ directive, but marks <symbol> as a zero/direct page symbol and use zero page addressing whenever <symbol> is used in a memory addressing mode.

longa on|off

Turns 16-bit accumulator width on or off. WDC-style alias for a16/a8 (WDC65816 only).

longi on|off

Turns 16-bit index register width on or off. WDC-style alias for x16/x8 (WDC65816 only).

setdp <expr>

Set the current base address of the zero/direct page for optimizations from absolute to direct-page addressing modes. Can be set to any 16-bit address on 65816 (defaults to zero). Is preset to $2000 for the HuC6280/PC-Engine.

x8

Declares that immediate instructions accessing the index registers have 8 bits width (default, WDC65816 only).

x16

Declares that immediate instructions accessing the index registers have 16 bits width (WDC65816 only).

xs

Alias for x8 (WDC65816 only).

xl

Alias for x16 (WDC65816 only).

zero

Switch to a zero/direct page section called zero or .zero, which has the type bss with attributes "aurwz". Accesses to symbols from this section will default to zero page addressing mode.

zpage <symbol1> [,<symbol2>...]

Mark symbols as zero/direct page and use zero page addressing for expressions based on this symbol, unless overridden by an addressing mode selector (like >).

All these directives are also available in the form starting with a dot (.).


26.5 Optimizations

This backend performs the following operand optimizations and translations:


26.6 Known Problems

Some known problems of this module at the moment:


26.7 Error Messages

This module has the following error messages:


[ << ] [ >> ]           [] [] [] [ ? ]