This chapter describes the oldstyle syntax module suitable for some 8-bit CPUs (6502, 680x, 68HC1x, Z80, etc.), which is available with the extension @code{oldstyle}. @section Legal This module is written in 2002-2018 by Frank Wille and is covered by the vasm copyright without modifications. @section Additional options for this module This syntax module provides the following additional options: @table @option @item -autoexp Automatically export all non-local symbols, making them visible to other modules during linking. @item -dotdir Directives have to be preceded by a dot (@code{.}). @item -i Ignore everything after a blank in the operand field and treat it as a comment. This option is only available when the backend does not separate its operands with blanks as well. @item -noc Disable C-style constant prefixes. @item -noi Disable intel-style constant suffixes. @end table @section General Syntax Labels always start at the first column and may be terminated by a colon (@code{:}), but don't need to. In the last case the mnemonic needs to be separated from the label by whitespace (not required in any case, e.g. @code{=}). Local labels are preceded by '@code{.}' or terminated by '@code{$}'. For the rest, any alphanumeric character including '@code{_}' is allowed. Local labels are valid between two global label definitions. It is allowed, but not recommended, to refer to any local symbol starting with '@code{.}' in the source, by preceding its name with the name of the last global symbol, which was defined before it: @code{global_name.local_name}. The operands are separated from the mnemonic by whitespace. Multiple operands are separated by comma (@code{,}). Make sure that you don't define a label on the same line as a directive for conditional assembly (if, else, endif)! This is not supported. Some CPU backends may supported multiple statements (directives or mnemonics) per line, separated by a special character (e.g. @code{:} for Z80). Comments are introduced by the comment character @code{;}, or the first blank following the operand field when option @option{-i} was given. The rest of the line will be ignored. Example: @code{mylabel instr op1,op2 ;comment} In expressions, numbers starting with @code{$} are hexadecimal (e.g. @code{$fb2c}). For Z80 also @code{&} may be used as a hexadecimal prefix, but make sure to avoid conflicts with the and-operator (either by using parentheses or blanks). @code{%} introduces binary numbers (e.g. @code{%1100101}). Numbers starting with @code{@@} are assumed to be octal numbers, e.g. @code{@@237} (except for Z80, where it means binary). A special case is a digit followed by a @code{#}, which can be used to define an arbitrary base between 2 and 9 (e.g. @code{4#3012}). Intel-style constant suffixes are supported: @code{h} for hexadecimal, @code{d} for decimal, @code{o} or @code{q} for octal and @code{b} for binary. Hexadecimal intel-style constants must start with a digit (prepend @code{0}, when required). Also C-style prefixes are supported for hexadecimal (@code{0x}) and binary (@code{0b}). All other numbers starting with a digit are decimal, e.g. @code{1239}. @section Directives The following directives are supported by this syntax module (if the CPU- and output-module allow it): @table @code @item = Equivalent to @code{ equ }. @item abyte ,[,,""...] Write the integer or string constant operands into successive bytes of memory in the current section while adding the constant to each byte. Any combination of integer and character string constant operands is permitted. @item addr [,...] Equivalent to @code{word [,...]}. @item align Insert as much zero bytes as required to reach an address where low order bits are zero. For example @code{align 2} would make an alignment to the next 32-bit boundary. @item asc [,,""...] Equivalent to @code{byte [,,""...]}. @item ascii [,,""...] See @code{defm}. @item asciiz ""[,""...] See @code{string}. @item assert [,] Display an error with the optional when the expression is false. @item binary Inserts the binary contents of into the object code at this position. The file will be searched first in the current directory, then in all paths defined by @option{-I} or @code{incdir} in the order of occurence. @item blk [,] Insert zero or bytes into the current section. @item blkw [,] Insert zero or 16-bit words into the current section, using the endianess of the target CPU. @item bsz [,] Equivalent to @code{blk [,]}. @item byt Increases the program counter by one. Equivalent to @code{blk 1,0}. @item byte [,,""...] Assign the integer or string constant operands into successive bytes of memory in the current section. Any combination of integer and character string constant operands is permitted. @item data [,,""...] Equivalent to @code{byte [,,""...]}. @item db [,,""...] Equivalent to @code{byte [,,""...]}. @item dc [,] Equivalent to @code{blk [,]}. @item defb [,,""...] Equivalent to @code{byte [,,""...]}. @item defc = Define a new program symbol with the name and assign to it the value of . Defining twice will cause an error. @item defl [,...] Assign the values of the operands into successive 32-bit integers of memory in the current section, using the endianess of the target CPU. @item defp [,...] Assign the values of the operands into successive 24-bit integers of memory in the current section, using the endianess of the target CPU. @item defm "string" Equivalent to @code{text "string"}. @item defw [,...] Equivalent to @code{word [,...]}. @item dfb [,,""...] Equivalent to @code{byte [,,""...]}. @item dfw [,...] Equivalent to @code{word [,...]}. @item defs [,] Equivalent to @code{blk [,]}. @item dephase Equivalent to @code{rend}. @item ds [,] Equivalent to @code{blk [,]}. @item dsb [,] Equivalent to @code{blk [,]}. @item dsw [,] Equivalent to @code{blkw [,]}. @item dw [,...] Equivalent to @code{word [,...]}. @item end Assembly will terminate behind this line. @item endif Ends a section of conditional assembly. @item el Equivalent to @code{else}. @item else Assemble the following lines when the previous @code{if}-condition was false. @item ei Equivalent to @code{endif}. (Not available for Z80 CPU) @item endm Ends a macro definition. @item endmac Ends a macro definition. @item endmacro Ends a macro definition. @item endr Ends a repetition block. @item endrep Ends a repetition block. @item endrepeat Ends a repetition block. @item endstruct Ends a structure definition. @item endstructure Ends a structure definition. @item eq Equivalent to @code{ equ }. @item equ Define a new program symbol with the name and assign to it the value of . Defining twice will cause an error. @item extern [,...] See @code{global}. @item even Aligns to an even address. Equivalent to @code{align 1}. @item fail Show an error message including the string. Do not generate an ouput file. @item fill Equivalent to @code{blk ,0}. @item fcb [,,""...] Equivalent to @code{byte [,,""...]}. @item fcc "" Equivalent to @code{text}. @item fdb [,,""...] Equivalent to @code{word [,...]}. @item global [,...] Flag as an external symbol, which means that is visible to all modules in the linking process. It may be either defined or undefined. @item if Conditionally assemble the following lines if is non-zero. @item ifdef Conditionally assemble the following lines if is defined. @item ifndef Conditionally assemble the following lines if is undefined. @item ifd Conditionally assemble the following lines if is defined. @item ifnd Conditionally assemble the following lines if is undefined. @item ifeq Conditionally assemble the following lines if is zero. @item ifne Conditionally assemble the following lines if is non-zero. @item ifgt Conditionally assemble the following lines if is greater than zero. @item ifge Conditionally assemble the following lines if is greater than zero or equal. @item iflt Conditionally assemble the following lines if is less than zero. @item ifle Conditionally assemble the following lines if is less than zero or equal. @item ifused Conditionally assemble the following lines if has been previously referenced in an expression or in a parameter of an opcode. Issue a warning, when is already defined. Note that @code{ifused} does not work, when the symbol has only been used in the following lines of the source. @item incbin [,[,]] Inserts the binary contents of into the object code at this position. When is specified, then the given number of bytes will be skipped at the beginning of the file. The optional argument specifies the maximum number of bytes to be read from that file. The file will be searched first in the current directory, then in all paths defined by @option{-I} or @code{incdir} in the order of occurence. @item incdir Add another path to search for include files to the list of known paths. Paths defined with @option{-I} on the command line are searched first. @item include Include source text of at this position. The include file will be searched first in the current directory, then in all paths defined by @option{-I} or @code{incdir} in the order of occurence. @item mac Equivalent to @code{macro }. @item list The following lines will appear in the listing file, if it was requested. @item local [,...] Flag as a local symbol, which means that is local for the current file and invisible to other modules in the linking process. @item macro [,...] Defines a macro which can be referenced by . The may also appear on the left side of the @code{macro} directive, starting at the first column. The macro definition is closed by an @code{endm} directive. When calling a macro you may pass up to 9 arguments, separated by comma. Those arguments are referenced within the macro context as @code{\1} to @code{\9}, or optionally by named arguments, which you have to specify in the operand. Argument @code{\0} is set to the macro's first qualifier (mnemonic extension), when given. The special argument @code{\@@} inserts an underscore followed by a six-digit unique id, useful for defining labels. @code{\()} may be used as a separator between the name of a macro argument and the subsequent text. @code{\} inserts the current decimal value of the absolute symbol @code{symbolname}. @item mdat Equivalent to @code{incbin }. @item nolist The following lines will not be visible in a listing file. @item org Sets the base address for the subsequent code. This is equivalent to @code{*=}. @item phase Equivalent to @code{rorg }. @item repeat Equivalent to @code{rept }. @item rept Repeats the assembly of the block between @code{rept} and @code{endr} number of times. has to be positive. @item reserve Equivalent to @code{blk ,0}. @item rend Ends a @code{rorg} block of label relocation. Following labels will be based on @code{org} again. @item rmb [,] Equivalent to @code{blk [,]}. (Not available for 6502 CPU.) @item roffs Sets the program counter bytes behind the start of the current section. The new program counter must not be smaller than the current one. The space will be padded with zeros. @item rorg Relocate all labels between @code{rorg} and @code{rend} based on the new origin from @code{}. @item section [,""] Starts a new section named or reactivate an old one. If attributes are given for an already existing section, they must match exactly. The section's name will also be defined as a new symbol, which represents the section's start address. The "" string may consist of the following characters: Section Contents: @table @code @item c section has code @item d section has initialized data @item u section has uninitialized data @item i section has directives (info section) @item n section can be discarded @item R remove section at link time @item a section is allocated in memory @end table Section Protection: @table @code @item r section is readable @item w section is writable @item x section is executable @item s section is sharable @end table @item set Create a new symbol with the name and assign the value of . If is already assigned, it will contain a new value from now on. @item spc Equivalent to @code{blk ,0}. @item string ""[,""...] Like @code{text}, but adds a terminating zero-byte. @item struct Defines a structure which can be referenced by . Labels within a structure definitation can be used as field offsets. They will be defined as local labels of @code{} and can be referenced through @code{.