This chapter describes the standard syntax module which is available with the extension @code{std}. @section Legal This module is written in 2002-2017 by Volker Barthelmann 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 -ac Immediately allocate common symbols in .bss/.sbss section and define them as externally visible. @item -align Enforces the backend's natural alignment for all data directives (@code{.word}, @code{.long}, @code{.float}, etc.). @item -nodotneeded Recognize assembly directives without a leading dot (@code{.}). @item -noesc Ignore escape character sequences in string constants. @item -sdlimit= Put data up to a maximum size of n bytes into the small-data sections. Default is n=0, which means the function is disabled. @end table @section General Syntax Labels have to be terminated with a colon (@code{:}). Local labels may either be preceded by a '@code{.}' or terminated by '@code{$}', and consist out of digits only. Local labels exist and keep their value between two global label definitions. 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. The operands are separated from the mnemonic by whitespace. Multiple operands are separated by comma (@code{,}). Comments are introduced by the comment character @code{#}. The rest of the line will be ignored. For the c16x, m68k, 650x, ARM, Z80, 6800 and Jaguar-RISC backends, the comment character is @code{;} instead of @code{#}, although @code{#} is still allowed when being the first non-blank character on a line. Example: @code{mylabel: inst.q1.q2 op1,op2,op3 # comment} In expressions, numbers starting with @code{0x} or @code{0X} are hexadecimal (e.g. @code{0xfb2c}). @code{0b} or @code{0B} introduces binary numbers (e.g. @code{0b1100101}). Other numbers starting with @code{0} are assumed to be octal numbers, e.g. @code{0237}. All numbers starting with a non-zero digit are decimal, e.g. @code{1239}. C-like escape characters in string constants are allowed by default, unless disabled by @option{-noesc}. @section Directives All directives are case-insensitive. The following directives are supported by this syntax module (if the CPU- and output-module allow it): @table @code @item .2byte [,...] See @code{.uahalf}. @item .4byte [,...] See @code{.uaword}. @item .8byte [,...] See @code{.uaquad}. @item .ascii [,,""...] See @code{.byte}. @item .abort Print an error and stop assembly immediately. @item .asciiz ""[,""...] See @code{.string}. @item .align [,][,] Depending on the current CPU backend @code{.align} either behaves like @code{.balign} (x86) or like @code{.p2align} (PPC). @item .balign [,][,] Insert as much fill bytes as required to reach an address which is dividable by . For example @code{.balign 2} would make an alignment to the next 16-bit boundary. The padding bytes are initialized by , when given. The optional third argument defines a maximum number of padding bytes to use. When more are needed then the alignment is not done at all. @item .balignl [,][,] Works like @code{.balign}, with the only difference that the optional fill value can be specified as a 32-bit word. Padding locations which are not already 32-bit aligned, will cause a warning and padded by zero-bytes. @item .balignw [,][,] Works like @code{.balign}, with the only difference that the optional fill value can be specified as a 16-bit word. Padding locations which are not already 16-bit aligned, will cause a warning and padded by zero-bytes. @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 .comm ,[,] Defines a common symbol which has a size of bytes. The final size and alignment will be assigned by the linker, which will use the highest size and alignment values of all common symbols with the same name found. A common symbol is allocated in the .bss section in the final executable. ".comm"-areas of less than 8 bytes in size are aligned to word boundaries, other- wise to doubleword boundaries. @item .double [,...] Parse one of more double precision floating point expressions and write them into successive blocks of 8 bytes into memory using the backend's endianess. @item .endm Ends a macro definition. @item .endr Ends a repetition block. @item .equ , See @code{.set}. @item .equiv , Assign the to similar to @code{.equ} and @code{.set}, but signals an error when has already been defined. @item .err Print a user error message. Do not create an output file. @item .extern [,...] See @code{.global}. @item .fail Cause a warning when is greater or equal 500. Otherwise cause an error. @item .file "string" Set the filename of the input source. This may be used by some output modules. By default, the input filename passed on the command line is used. @item .float [,...] Parse one of more single precision floating point expressions and write them into successive blocks of 4 bytes into memory using the backend's endianess. @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 .globl [,...] See @code{.global}. @item .half [,...] Assign the values of the operands into successive 16-bit words of memory in the current section using the backend's endianess. @item .if Conditionally assemble the following lines if is non-zero. @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 .ifb Conditionally assemble the following lines when is completely blank, except an optional comment. @item .ifnb Conditionally assemble the following lines when is non-blank. @item .ifdef Conditionally assemble the following lines if is defined. @item .ifndef Conditionally assemble the following lines if is undefined. @item .incbin 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 .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 .int [,...] See @code{.long}. @item .irp [,...] Iterates the block between @code{.irp} and @code{.endr} for each @code{}. The current @code{}, which may be embedded in quotes, is assigned to @code{\symbol}. If no value is given, then the block is assembled once, with @code{\symbol} set to an empty string. @item .irpc [,...] Iterates the block between @code{.irp} and @code{.endr} for each character in each @code{}, and assign it to @code{\symbol}. If no value is given, then the block is assembled once, with @code{\symbol} set to an empty string. @item .lcomm ,[,] Allocate bytes of space in the .bss section and assign the value to that location to . If is given, then the space will be aligned to an address having low zero bits or 2, whichever is greater. may be made globally visible by the .globl directive. @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 .long [,...] Assign the values of the operands into successive 32-bit words of memory in the current section using the backend's endianess. @item .macro [[=][,...]] Defines a macro which can be referenced by . The macro definition is closed by an @code{.endm} directive. The names of the arguments, which may be passed to this macro, must be declared directly following the macro name. You can define an optional default value in the case an argument is left out. Note that macro names are case-insensitive while the argument names are case-sensitive. Within the macro context arguments are referenced by @code{\argname}. The special argument @code{\@@} inserts a unique id, useful for defining labels. @code{\()} may be used as a separator between the name of a macro argument and the subsequent text. @item .nolist The following lines will not be visible in a listing file. @item .org Before any other section directive @code{} defines the absolute start address of the program. Within a section @code{} defines the offset from the start of this section for the subsequent code. When starts with a current-pc symbol followed by a plus (@code{+}) operator, then the directive behaves like @code{.space}. @item .p2align [,][,] Insert as much fill bytes as required to reach an address where low order bits are zero. For example @code{.p2align 2} would make an alignment to the next 32-bit boundary. The padding bytes are initialized by , when given. The optional third argument defines a maximum number of padding bytes to use. When more are needed then the alignment is not done at all. @item .p2alignl [,][,] Works like @code{.p2align}, with the only difference that the optional fill value can be specified as a 32-bit word. Padding locations which are not already 32-bit aligned, will cause a warning and padded by zero-bytes. @item .p2alignw [,][,] Works like @code{.p2align}, with the only difference that the optional fill value can be specified as a 16-bit word. Padding locations which are not already 16-bit aligned, will cause a warning and padded by zero-bytes. @item .quad [,...] Assign the values of the operands into successive quadwords (64-bit) of memory in the current section using the backend's endianess. @item .rept Repeats the assembly of the block between @code{.rept} and @code{.endr} number of times. has to be positive. @item .section [,""][[,@@]|[,%]|[,]] Starts a new section named @code{} 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 @code{""} 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 Section Alignment: A digit, which is ignored. The assembler will automatically align the section to the highest alignment restriction used within. Memory flags (Amiga hunk format only): @table @code @item C load section to Chip RAM @item F load section to Fast RAM @end table The optional @code{} argument is mainly used for ELF output and may be introduced either by a '%' or a '@@' character. Allowed are: @table @code @item progbits This is the default value, which means the section data occupies space in the file and may have initialized data. @item nobits These sections do not occupy any space in the file and will be allocated filled with zero bytes by the OS loader. @end table When the optional, non-standard, @code{} argument is given it defines a 32-bit memory attribute, which defines where to load the section (platform specific). The memory attributes are currently only used in the hunk-format output module. @item .set , Create a new program symbol with the name and assign to it the value of . If is already assigned, it will contain a new value from now on. @item .size , Set the size in bytes of an object defined at . @item .short [,...] See @code{.half}. @item .single [,...] Same as @code{.float}. @item .skip [,] Insert zero or bytes into the current section. @item .space [,] Insert zero or bytes into the current section. @item .stabs "",,,, Add an stab-entry for debugging, including a symbol-string and an expression. @item .stabn ,,, Add an stab-entry for debugging, without a symbol-string. @item .stabd ,, Add an stab-entry for debugging, without symbol-string and value. @item .string ""[,""...] Like @code{.byte}, but adds a terminating zero-byte. @item .swbeg Just for compatibility. Do nothing. @item .type , Set type of symbol called to , which must be one of: @table @code @item 1: Object @item 2: Function @item 3: Section @item 4: File @end table The predefined symbols @code{@@object} and @code{@@function} are available for this purpose. @item .uahalf [,...] Assign the values of the operands into successive 16-bit areas of memory in the current section regardless of current alignment. @item .ualong [,...] Assign the values of the operands into successive 32-bit areas of memory in the current section regardless of current alignment. @item .uaquad [,...] Assign the values of the operands into successive 64-bit areas of memory in the current section regardless of current alignment. @item .uashort [,...] Assign the values of the operands into successive 16-bit areas of memory in the current section regardless of current alignment. @item .uaword [,...] Assign the values of the operands into successive 16-bit areas of memory in the current section regardless of current alignment. @item .weak [,...] Flag as a weak symbol, which means that is visible to all modules in the linking process and may be replaced by any global symbol with the same name. When a weak symbol remains undefined its value defaults to 0. @item .word [,...] Assign the values of the operands into successive 16-bit words of memory in the current section using the backend's endianess. @item .zero [,] Insert zero or bytes into the current section. @end table Predefined section directives: @table @code @item .bss .section ".bss","aurw" @item .data .section ".data","adrw" @item .rodata .section ".rodata","adr" @item .sbss .section ".sbss","aurw" @item .sdata .section ".sdata","adrw" @item .sdata2 .section ".sdata2","adr" @item .stab .section ".stab","dr" @item .stabstr .section ".stabstr","dr" @item .text .section ".text","acrx" @item .tocd .section ".tocd","adrw" @end table @section Known Problems Some known problems of this module at the moment: @itemize @minus @item None. @end itemize @section Error Messages This module has the following error messages: @itemize @minus @item 1001: mnemonic expected @item 1002: invalid extension @item 1003: no space before operands @item 1004: too many closing parentheses @item 1005: missing closing parentheses @item 1006: missing operand @item 1007: scratch at end of line @item 1008: section flags expected @item 1009: invalid data operand @item 1010: memory flags expected @item 1011: identifier expected @item 1012: assembly aborted @item 1013: unexpected "%s" without "%s" @item 1014: pointless default value for required parameter <%s> @item 1015: invalid section type ignored, assuming progbits @item 1019: syntax error @item 1021: section name expected @item 1022: .fail %lld encountered @item 1023: .fail %lld encountered @item 1024: alignment too big @end itemize