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

@section Legal

    This module is copyright in 2002,2006,2008-2011 by Frank Wille.

    This archive may be redistributed without modifications and used
    for non-commercial purposes.

    Distributing modified versions and commercial usage needs my written
    consent.

    Certain modules may fall under additional copyrights.


@section Additional options for this module

This module provides the following additional options:

@table @option
    @item -dtv
        Recognize the three additional C64-DTV instructions.
    @item -illegal
        Allow 'illegal' 6502 instructions to be recognized.
    @item -opt-branch
        Enables 'optimization' of B<cc> branches into
        "B<!cc> *+3 ; JMP label" sequences when necessary.
@end table

@section 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.
@code{dcm} and @code{dcp} refer to the same instruction). Some illegal
insructions (e.g. @code{$ab}) are known to show unpredictable behaviour,
or do not always work the same on different CPUs.

@section Extensions

This backend provides the following specific extensions:

@itemize @minus

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

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

@end itemize

@section Optimizations

This backend performs the following operand optimizations:

@itemize @minus

@item Branches, where the destination is out of range, are translated
 into @code{B<!cc> *+3} and an absolute @code{JMP} instruction.

@end itemize

@section Known Problems

    Some known problems of this module at the moment:

@itemize @minus

@item None.

@end itemize

@section Error Messages

This module has the following error messages:

@itemize @minus

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

@end itemize
