Line can begin with a label. Label should be followed by ":", but it can be omitted.
Everything after a ; in a line is a comment (unless the ; is part of a string literal, of course). There are no multiline comments.
String literals are written to the object file without any character set translation. In case you use punctuated character, the lower byte of its Unicode representation will be used.
Blanks are significative only in string literals and when they separate lexical elements. Any number of blanks has the same meaning as one. A blank between operators and operands is allowed but no required except when the same character has other meaning as prefix ('$' and '%', for example).
Numeric literals can be written in decimal, binary, octal and hexadecimal formats. Several formats are accepted to obtain compatibility with the source format of several assemblers.
A literal that begins with $ is a hexadecimal constant, except if the literal is only the $ symbol.
A literal that begins with % is a binary constant, except if the literal is only the % symbol, in that case, is an operator.
A literal that begins with a decimal digit can be a decimal, binary, octal or hexadecimal. If the digit is 0 and the following character is an X, the number is hexadecimal. If not, the suffix of the literal is examined: D means decimal, B binary, H hexadecimal and O or Q octal, in any other case, is taken as a decimal. Take care, FFFFh, for example, is not a hexadecimal constant, is an identifier, to write it with the suffix notation you must do it as 0FFFFh.
There is one format of string literals. They should be double quote delimited. Assembler can parse single quote form too, but it should produce an error, when delimitation is used in string, so please use double quotes.
A string literal of length 1 can be used as a numeric constant with the numeric value of the character contained. This allows expressions such as 'A' + 80h to be evaluated as expected.
Identifiers are the names used for labels, EQU symbols and macro names and parameters. The names of the CPU mnemonics, registers, and flag names, and of assembling directives are reserved and can not be used as names of identifiers. Reserved names are case insensitive, even if case sensitive mode is used.
Identifiers are not case sensitive. Internally are converted to uppercase
Parser can evaluate simple math expressions, with all of the common operators, like +, -, /, *, # (modulo). You can use identifiers as a variables too, e.g. "LOOP + 3".
There are some specials here, like string repetitions ("A"*3 produces "AAA") or upper / lower part of identifier value. If LOOP is 0x1234, then <LOOP means 0x34, >LOOP means 0x12
Right CPU is determined by file name extension, or by .engine directive (see below). File name extensions are:
|.cpu||Select CPU type. Available values are: 8080, Z80, 6502, M6800, CDP1802, M6809, C65816|
|.engine||Controls machine type for emulation (only in online ASM80). Available values are: PMI, PMD, JPR, KIM, SBCZ80, SBC6502, SBC09, ZXS and CPM|
|.pragma sna||Makes SNA file instead of HEX (only for Z80)|
|.pragma tap||Makes TAP file instead of HEX (only for Z80)|
|.pragma prg||Makes C64's PRG file instead of HEX (only for 6502) [read more]
.PRAGMA PRG ;says “make .PRG instead of .HEX” .ORG $0810 ;or higher .ENT $ ;for “enter here”
|.pragma com||Makes CP/M COM file instead of HEX (only for Z80/8080) [read more]|
|.pragma html||Makes HTML listing (instead of LPT)|
|db (aliases: defb, fcb)||Define Byte. The argument is a comma separated list of string literals or numeric expressions. The string literals are inserted in the object code, and the result of the numeric expression is inserted as a single byte, truncating it if needed. You can use DUP for entering N same values: DB 10 DUP (123) means "10 times value 123"|
|dw (aliases: defw, fdb)||Define Word. The argument is a comma separated list of numeric expressions. Each numeric expression is evaluated as a two byte word and the result inserted in the proper "endianity". You can use DUP for entering N same values: DW 10 DUP (123) means "10 times value 123"|
|ds (aliases: defm, defs, rmb)||Define Space. Take one argument, which is the amount of space to define, in bytes.|
|fill value, length||Fill memory with a value. Take two arguments, the first is a value, the second is length of filled block (byte count).|
|bsz length (alias: zmb)||Fill memory with a given count of zeros.|
|.include filename||Include a file. The file is readed and the result is the same as if the file were copied in the current file instead of the INCLUDE line. The file included may contain INCLUDE directives, and so on. INCLUDE directives are processed before the assembly phases, so the use of IF directives to conditionally include different files is not allowed.|
|org addr||ORiGin. Establishes the origin position where to place generated code. Several ORG directives can be used in the same program, but if the result is that code generated overwrites previous, the result is undefined.|
|.ent addr||ENTer point for debugging. I.e. .ent $|
|.align N||The .align directive causes the next data generated to be aligned modulo N bytes.|
|.phase addr||Continue to produce code and data for loading at the current address but assemble instructions and define labels as if they originated at the given address. Useful when producing code that will be copied to a different location before being executed.|
|.dephase||End phase block.|
|equ (alias: =)||EQUate. Must be preceded by a label. The argument must be a numeric expression, the result is assigned to the label. I.e. VIDRAM equ $4000|
|.if cond||Contional assembly. The argument must be a numeric expression, a result of 0 is considered as false, any other as true. If the argument is true the following code is assembled until the end of the IF section is encountered, else is ignored. The IF section is ended with a ENDIF directive. IF can't be nested.|
|.ifn cond||IF NOT|
|.endif||End of the IF block|
|Macros and blocks|
|.macro macro_name||Defines a macro, see the chapter about macros.|
|.rept count||Repeat a block of code substituing arguments. See the chapter about macros.|
|.endm||End of MACRO definition or REPT cycle.|
|.block||Start of logical block. All labels, defined in this block, are local. It means you can’t reference them from outside the block. If you want to define a label globally, simply prefix it with ‘@’, like @LABEL:
Good idea is to enclose INCLUDEd code into block.
|.endblock||End of BLOCK.|
|.m8||Accumulator is 8bit|
|.x8||index register is 8bit|
Define macro with .macro and .endm. You can use a parametric macros - any parameter is addressable by %%1, %%2, %%3, ... For example, such code:
.macro decadd adi %%1 daa .endm ; Use this macro decadd $22
will generate this:
0000 ; Use this macro **MACRO UNROLL - DECADD 0000 87 22 ADI $22 0001 27 DAA