Next Previous Contents

4. Input format

4.1 Assembler syntax

The assembler accepts the standard 6502/65816 assembler syntax. One line may contain a label (which is identified by a colon), and, in addition to the label, an assembler mnemonic, a macro, or a control command (see section Control Commands for supported control commands). Alternatively, the line may contain a symbol definition using the '=' token. Everything after a semicolon is handled as a comment (that is, it is ignored).

Here are some examples for valid input lines:

        Label:                          ; A label and a comment
                lda     #$20            ; A 6502 instruction plus comment
        L1:     ldx     #$20            ; Same with label
        L2:     .byte   "Hello world"   ; Label plus control command
                mymac   $20             ; Macro expansion
                MySym = 3*L1            ; Symbol definition
        MaSym   = Label                 ; Another symbol

The assembler accepts

4.2 65816 mode

In 65816 mode several aliases are accepted in addition to the official mnemonics:

        BGE is an alias for BCS
        BLT is an alias for BCC
        CPA is an alias for CMP
        DEA is an alias for DEC A
        INA is an alias for INC A
        SWA is an alias for XBA
        TAD is an alias for TCD
        TAS is an alias for TCS
        TDA is an alias for TDC
        TSA is an alias for TSC

4.3 6502X mode

6502X mode is an extension to the normal 6502 mode. In this mode, several mnemonics for illegal instructions of the NMOS 6502 CPUs are accepted. Since these instructions are illegal, there are no official mnemonics for them. The unofficial ones are taken from http://www.oxyron.de/html/opcodes02.html. Please note that only the ones marked as "stable" are supported. The following table uses information from the mentioned web page, for more information, see there.

4.4 sweet16 mode

SWEET 16 is an interpreter for a pseudo 16 bit CPU written by Steve Wozniak for the Apple ][ machines. It is available in the Apple ][ ROM. ca65 can generate code for this pseudo CPU when switched into sweet16 mode. The following is special in sweet16 mode:

Please note that the assembler does neither supply the interpreter needed for SWEET 16 code, nor the zero page locations needed for the SWEET 16 registers, nor does it call the interpreter. All this must be done by your program. Apple ][ programmers do probably know how to use sweet16 mode.

For more information about SWEET 16, see http://www.6502.org/source/interpreters/sweet16.htm.

4.5 Number format

For literal values, the assembler accepts the widely used number formats: A preceding '$' or a trailing 'h' denotes a hex value, a preceding '%' denotes a binary value, and a bare number is interpreted as a decimal. There are currently no octal values and no floats.

4.6 Conditional assembly

Please note that when using the conditional directives (.IF and friends), the input must consist of valid assembler tokens, even in .IF branches that are not assembled. The reason for this behaviour is that the assembler must still be able to detect the ending tokens (like .ENDIF), so conversion of the input stream into tokens still takes place. As a consequence conditional assembly directives may not be used to prevent normal text (used as a comment or similar) from being assembled.


Next Previous Contents