'    assembly code here
'    more assembly code

The ASM directive injects bare 6502 assembly code into the compiled XC=BASIC code without any modification. As XC=BASIC itself produces DASM code, the injected assembly code must also be in DASM format and syntax.


Each line within the ASM … END ASM block must start with a single quote ( ' ) character or the REM keyword in order to prevent the compiler from interpreting it as BASIC code.

For a more comprehensive tutorial on using 6502 assembly with XC=BASIC, see this page. TBD


REM -- set border to black using XC=BASIC code
POKE $d020, 0
REM -- set background to black using inline assembly
'   lda #$00
'   sta $d021
REM -- the XC=BASIC program continues on from here

The above example illustrates how to use ASM to inject inline assembly code into the XC=BASIC program. The compiler will send the code between the ASM … END ASM commands straight to DASM for assembly immediately following the POKE command. Newlines are used in this example to improve the readability of 6502 assembly code that spans beyond one line. Note there are no quotation marks or other encapsulations around the assembly code as was previously required in XC=BASIC v2.

Note the spaces before the opcodes on each line of DASM assembly code. Leading spaces are required by DASM for any line of assembly that is not a valid DASM label.


Each line in DASM assembly code must start with a label or at least one space.


The XC=BASIC compiler cannot validate the in-line assembly code. It will be copied verbatim into the XC=BASIC assembly before being compiled by DASM, so you must take special care with the ASM directive. DASM will report any errors. Please consult the DASM docs carefully for syntax and formatting.

Using 6502 Assembly in XC=BASIC Programs

As was done with the v2 extensions tutorial, a page might be put together to more comprehensively explain how to use in-line assembly in XC=BASIC programs. This page and the v3 extensions tutorial should reference it.