3.6. Assembler Directives

Various directives can be used to control the behaviour of the assembler or to include non-code/data in the resulting output. Those directives that are not described in detail in other sections of this document are described below.

3.6.1. Data Directives

FCB expr[,...], .DB expr[,...], .BYTE expr[,...]

Include one or more constant bytes (separated by commas) in the output.

FDB expr[,...], .DW expr[,...], .WORD expr[,...]

Include one or more words (separated by commas) in the output.

FQB expr[,...], .QUAD expr[,...], .4BYTE expr[,...]

Include one or more double words (separated by commas) in the output.

FCC string, .ASCII string, .STR string

Include a string of text in the output. The first character of the operand is the delimiter which must appear as the last character and cannot appear within the string. The string is included with no modifications>

FCN string, .ASCIZ string, .STRZ string

Include a NUL terminated string of text in the output. The first character of the operand is the delimiter which must appear as the last character and cannot appear within the string. A NUL byte is automatically appended to the string.

FCS string, .ASCIS string, .STRS string

Include a string of text in the output with bit 7 of the final byte set. The first character of the operand is the delimiter which must appear as the last character and cannot appear within the string.

ZMB expr

Include a number of NUL bytes in the output. The number must be fully resolvable during pass 1 of assembly so no forward or external references are permitted.

ZMD expr

Include a number of zero words in the output. The number must be fully resolvable during pass 1 of assembly so no forward or external references are permitted.

ZMQ expr

Include a number of zero double-words in the output. The number must be fully resolvable during pass 1 of assembly so no forward or external references are permitted.

RMB expr, .BLKB expr, .DS expr, .RS expr

Reserve a number of bytes in the output. The number must be fully resolvable during pass 1 of assembly so no forward or external references are permitted. The value of the bytes is undefined.

RMD expr

Reserve a number of words in the output. The number must be fully resolvable during pass 1 of assembly so no forward or external references are permitted. The value of the words is undefined.

RMQ expr

Reserve a number of double-words in the output. The number must be fully resolvable during pass 1 of assembly so no forward or external references are permitted. The value of the double-words is undefined.

INCLUDEBIN filename

Treat the contents of filename as a string of bytes to be included literally at the current assembly point. This has the same effect as converting the file contents to a series of FCB statements and including those at the current assembly point.

If filename beings with a /, the file name will be taken as absolute. Otherwise, the current directory will be searched followed by the search path in the order specified.

Please note that absolute path detection including drive letters will not function correctly on Windows platforms. Non-absolute inclusion will work, however.

FILL size,byte

Insert size bytes of byte.

3.6.2. Address Definition

The directives in this section all control the addresses of symbols or the assembly process itself.

ORG expr

Set the assembly address. The address must be fully resolvable on the first pass so no external or forward references are permitted. ORG is not permitted within sections when outputting to object files. For target formats that include address information (decb, hex, srec, and ihex), an ORG directive will re-start the address sequence within the output. When using the raw target format, ORG is used only to determine the addresses of symbols.

REORG

Sets the assembly address to the value it had immediately prior to the previous ORG statement. It is used to continue assembly after some specification that required an additional ORG. This directive is primarily intended for MACRO-80c compatibility. Consider using alternatives in modern code.

sym EQU expr, sym = expr

Define the value of sym to be expr.

sym SET expr

Define the value of sym to be expr. Unlike EQU, SET permits symbols to be defined multiple times as long as SET is used for all instances. Use of the symbol before the first SET statement that sets its value is undefined.

SETDP expr

Inform the assembler that it can assume the DP register contains expr. This directive is only advice to the assembler to determine whether an address is in the direct page and has no effect on the contents of the DP register. The value must be fully resolved during the first assembly pass because it affects the sizes of subsequent instructions.

This directive has no effect in the object file target.

ALIGN expr[,value]

Force the current assembly address to be a multiple of expr. If value is not specified, a series of NUL bytes is output to force the alignment, if required. Otherwise, the low order 8 bits of value will be used as the fill. The alignment value must be fully resolved on the first pass because it affects the addresses of subsquent instructions. However, value may include forward references; as long as it resolves to a constant for the second pass, the value will be accepted.

Unless value is specified as something like $12, this directive is not suitable for inclusion in the middle of actual code. The default padding value is $00 which is intended to be used within data blocks.

3.6.3. Conditional Assembly

Portions of the source code can be excluded or included based on conditions known at assembly time. Conditionals can be nested arbitrarily deeply. The directives associated with conditional assembly are described in this section.

All conditionals must be fully bracketed. That is, every conditional statement must eventually be followed by an ENDC at the same level of nesting.

Conditional expressions are only evaluated on the first assembly pass. It is not possible to game the assembly process by having a conditional change its value between assembly passes. Due to the underlying architecture of LWASM, there is no possible utility to IFP1 and IFP2, nor can they, as of LWASM 3.0, actually be implemented meaningfully. Thus there is not and never will be any equivalent of IFP1 or IFP2 as provided by other assemblers. Use of those opcodes will throw a warning and be ignored.

It is important to note that if a conditional does not resolve to a constant during the first parsing pass, an error will be thrown. This is unavoidable because the assembler must make a decision about which source to include and which source to exclude at this stage. Thus, expressions that work normally elsewhere will not work for conditions.

IFEQ expr

If expr evaluates to zero, the conditional will be considered true.

IFNE expr, IF expr

If expr evaluates to a non-zero value, the conditional will be considered true.

IFGT expr

If expr evaluates to a value greater than zero, the conditional will be considered true.

IFGE expr

If expr evaluates to a value greater than or equal to zero, the conditional will be considered true.

IFLT expr

If expr evaluates to a value less than zero, the conditional will be considered true.

IFLE expr

If expr evaluates to a value less than or equal to zero , the conditional will be considered true.

IFDEF sym

If sym is defined at this point in the assembly process, the conditional will be considered true.

IFPRAGMA pragma

If pragma is in effect, the condition will be considered true.

IFNDEF sym

If sym is not defined at this point in the assembly process, the conditional will be considered true.

ELSE

If the preceding conditional at the same level of nesting was false, the statements following will be assembled. If the preceding conditional at the same level was true, the statements following will not be assembled. Note that the preceding conditional might have been another ELSE statement although this behaviour is not guaranteed to be supported in future versions of LWASM.

ENDC

This directive marks the end of a conditional construct. Every conditional construct must end with an ENDC directive.

3.6.4. OS9 Target Directives

This section includes directives that apply solely to the OS9 target.

OS9 syscall

This directive generates a call to the specified system call. syscall may be an arbitrary expression.

MOD size,name,type,flags,execoff,datasize

This tells LWASM that the beginning of the actual module is here. It will generate a module header based on the parameters specified. It will also begin calcuating the module CRC.

The precise meaning of the various parameters is beyond the scope of this document since it is not a tutorial on OS9 module programming.

EMOD

This marks the end of a module and causes LWASM to emit the calculated CRC for the module.

3.6.5. Miscelaneous Directives

This section includes directives that do not fit into the other categories.

INCLUDE filename, USE filename

Include the contents of filename at this point in the assembly as though it were a part of the file currently being processed. Note that if whitespace appears in the name of the file, you must enclose filename in quotes.

Note that the USE variation is provided only for compatibility with other assemblers. It is recommended to use the INCLUDE variation.

If filename begins with a "/", it is interpreted as an absolute path. If it does not, the search path will be used to find the file. First, the directory containing the file that contains this directive. (Includes within an included file are relative to the included file, not the file that included it.) If the file is not found there, the include path is searched. If it is still not found, an error will be thrown. Note that the current directory as understood by your shell or operating system is not searched.

END [expr]

This directive causes the assembler to stop assembling immediately as though it ran out of input. For the DECB target only, expr can be used to set the execution address of the resulting binary. For all other targets, specifying expr will cause an error.

ERROR string

Causes a custom error message to be printed at this line. This will cause assembly to fail. This directive is most useful inside conditional constructs to cause assembly to fail if some condition that is known bad happens. Everything from the directive to the end of the line is considered the error message.

WARNING string

Causes a custom warning message to be printed at this line. This will not cause assembly to fail. This directive is most useful inside conditional constructs or include files to alert the programmer to a deprecated feature being used or some other condition that may cause trouble later, but which may, in fact, not cause any trouble.

.MODULE string

This directive is ignored for most output targets. If the output target supports encoding a module name into it, string will be used as the module name.

As of version 3.0, no supported output targets support this directive.