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

- all valid 6502 mnemonics when in 6502 mode (the default or after the `.P02` command was given).
- all valid 6502 mnemonics plus a set of illegal instructions when in 6502X mode.
- all valid 65SC02 mnemonics when in 65SC02 mode (after the `.PSC02` command was given).
- all valid 65C02 mnemonics when in 65C02 mode (after the `.PC02` command was given).
- all valid 65618 mnemonics when in 65816 mode (after the `.P816` command was given).
- all valid SunPlus mnemonics when in SunPlus mode (after the `.SUNPLUS` command was given).

## 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://oxyron.net/graham/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.

- `ALR: A:=(A and #{imm})/2;`
- `ANC: A:=A and #{imm};` Generates opcode $0B.
- `ARR: A:=(A and #{imm})/2;`
- `AXS: X:=A and X-#{imm};`
- `DCP: {adr}:={adr}-1; A-{adr};`
- `ISC: {adr}:={adr}+1; A:=A-{adr};`
- `LAS: A,X,S:={adr} and S;`
- `LAX: A,X:={adr};`
- `RLA: {adr}:={adr}rol; A:=A and {adr};`
- `RRA: {adr}:={adr}ror; A:=A adc {adr};`
- `SAX: {adr}:=A and X;`
- `SLO: {adr}:={adr}*2; A:=A or {adr};`
- `SRE: {adr}:={adr}/2; A:=A xor {adr};`

## 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:

- The '@' character denotes indirect addressing and is no longer available for cheap local labels. If you need cheap local labels, you will have to switch to another lead character using the `.LOCALCHAR` command.
- Registers are specified using `R0` .. `R15`. In sweet16 mode, these identifiers are reserved words.

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