This chapter documents the backend for the MOS/Rockwell 6502
microprocessor family.

1 Legal
=======

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

2 Additional options for this module
====================================

This module provides the following additional options:

'-c02'
     Recognize all 65C02 instructions.  This excludes DTV ('-dtv') and
     illegal ('-illegal') instructions.
'-dtv'
     Recognize the three additional C64-DTV instructions.
'-illegal'
     Allow 'illegal' 6502 instructions to be recognized.
'-opt-branch'
     Enables 'optimization' of B<cc> branches into "B<!cc> *+3 ; JMP
     label" sequences when necessary.

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, 65C02, 65CE02, 65C102, 65C112, 6503, 6504,
6505, 6507, 6508, 6509, 6510, 6511, 65F11, 6512 - 6518, 65C00/21, 65C29,
6570, 6571, 6280, 6702, 740, 7501, 8500, 8502, 65802, 65816.

   The target address type is 16 bit.

   Instructions consist of one up to three bytes and require no
alignment.  There is also no alignment requirement for sections and
data.

   All known mnemonics for illegal instructions are 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.

4 Extensions
============

This backend provides the following specific extensions:

   - The parser understands a lo/hi-modifier to select low- or high-byte
     of a 16-bit word.  The character '<' is used to select the low-byte
     and '>' for the high-byte.  It has to be the first character before
     an expression.

   - When applying the operation '/256', '%256' or '&256' on a label, an
     appropriate lo/hi-byte relocation will automatically be generated.

5 Optimizations
===============

This backend performs the following operand optimizations:

   - Branches, where the destination is out of range, are translated
     into 'B<!cc> *+3' and an absolute 'JMP' instruction.

6 Known Problems
================

Some known problems of this module at the moment:

   - None.

7 Error Messages
================

This module has the following error messages:

   - 2001: instruction not supported on selected architecture
   - 2002: trailing garbage in operand
   - 2003: missing closing parenthesis in addressing mode
   - 2004: data size %d not supported
   - 2005: relocation does not allow hi/lo modifier
   - 2006: operand doesn't fit into 8-bits
   - 2007: branch destination out of range

