This chapter describes the directives that are available for the assembler.
NOTE Some directives are not available for every assembler.
By default, most directives must begin with a period (.). However if you clear the Directives begin with '.' checkbox of the Assembler settings panel, you can omit the period.
NOTE You can specify several preprocessor directives using the C/C++ preprocessor format.
This chapter discusses the following topics:
The following directives let you create macros:
For more information on macros, see "Using Macros".
label .macro [ parameter ] [ ,parameter ] ...
Begins the definition of a macro named label, with the specified parameters.
endm
.endm
.mexit
Causes the assembler to stop macro processing before the .endm statement is reached and resume execution with the statement following the macro call.
#define name [ (parms) ] assembly_statement [ ; ] [ \ ] assembly_statement [ ; ] [ \ ] assembly_statement parms ::= parameter [ ,parameter ]...
Defines a macro named name with the specified parameters. You can extend assembly_statement by typing a backslash (\) and continuing the statement on the next physical line. You also can specify multiple assembly statements in the macro by typing a semicolon (;) followed by a backslash (\) and typing a new assembly statement on the next physical line. For more information, see "Defining a macro with the #define directive".
NOTE The #define directive is a preprocessor directive.
Conditional directives create a conditional assembly block. If you wrap some code with .ifdef and .endif you can control whether that code is included in compilation. This is useful for making several different builds that are slightly different.
You must use conditional directives together to form a complete block. The assembler also contains several variations of .if to make it easier to make blocks that test strings for equality, test whether a symbol is defined, and so on.
NOTE You can specify several of the conditional preprocessor directives using the C/C++ preprocessor format:
#if
#ifdef
#ifndef
#else
#elif
#endif
These directives function identically whether preceded by a pound sign (#) or a period with two exceptions. You cannot use the pound sign form of the directive in a macro, and the period (.) form of the #elif directive is .elseif.
This section discusses the following topics:
.if bool-expr
Specifies the beginning of a conditional assembly block, where bool-expr is a Boolean expression. If bool-expr is true, the assembler processes the statements associated with the .if directive. If bool-expr is false, the assembler skips the statements associated with the .if directive.
Each .if directive must have a matching .endif directive.
NOTE A Boolean expression is a special type of arithmetic expression. The assembler interprets a Boolean expression that evaluates to zero as false and a Boolean expression that evaluates to a nonzero result as true. For more information on expressions, see "Expressions".
.ifdef symbol
Specifies the beginning of a conditional assembly block and tests whether symbol is already defined. If symbol was defined previously, the assembler processes the statements associated with the .ifdef directive. If symbol is not yet defined, the assembler skips the statements associated with the .ifdef directive.
Each .ifdef directive must have a matching .endif directive.
.ifndef symbol
Specifies the beginning of a conditional assembly block and tests whether symbol is not yet defined. If symbol is not yet defined, the assembler processes the statements associated with the .ifndef directive. If symbol is already defined, the assembler skips the statements associated with the .ifndef directive.
Each .ifndef directive must have a matching .endif directive.
.ifc string1, string2
Specifies the beginning of a conditional assembly block and tests whether string1 and string2 are equal. The comparison is case-sensitive. If the strings are equal, the assembler processes the statements associated with the .ifc directive. If the strings are not equal, the assembler skips the statements associated with the .ifc directive.
Each .ifc directive must have a matching .endif directive.
.ifnc string1, string2
Specifies the beginning of a conditional assembly block and tests whether string1 and string2 are not equal. The comparison is case-sensitive. If the strings are not equal, the assembler processes the statements associated with the .ifnc directive. If the strings are equal, the assembler skips the statements associated with the .ifnc directive.
Each .ifnc directive must have a matching .endif directive.
.endif
Specifies the end of a conditional assembly block. Each type of .if directive must have a matching .endif directive.
.elseif bool-expr
You can use the .elseif directive to create a series of directives that together comprise a logical multilevel if-then-else statement, the syntax of which follows:
.if bool-expr statement-group [ .elseif bool-expr statement-group ]...
[ .else statement-group ]
.endif
In the preceding syntax statement, bool-expr is any Boolean expression and statement-group is any group of assembly language statements.
Expanding the syntax as follows helps to explain the flow of the statement:
.if bool-expr-1 statement-group-1
.elseif bool-expr-2
statement-group-2
.elseif bool-expr-3
statement-group-3
.elseif bool-expr-4
statement-group-4
.else
statement-group-5
.endif
In the preceding syntax statement, if bool-expr-1 is true, the assembler executes statement-group-1 (the first group of conditional assembly language statements) and goes to the .endif directive. If bool-expr-1 is false, the assembler skips statement-group-1 and tests bool-expr-2 in the first .elseif directive.
If bool-expr-2 is true, the assembler executes statement-group-2 and goes to the .endif directive. If bool-expr-2 is false, the assembler skips statement-group-2 and tests bool-expr-3 in the second .elseif directive.
The assembler continues evaluating the Boolean expressions in succeeding .elseif directives until it comes to a Boolean expression that evaluates to true. If none of the .elseif directives have a Boolean expression that evaluates to true, the assembler processes the statements associated with the .else directive, if there is one.
.else
Marks the beginning of a conditional assembly block to execute if the Boolean expressions for an .if directive and its associated .elseif directives are false.
NOTE Using an .else directive is optional.
For compatibility with other assemblers, the assembler also supports the following directives:
.ifeq (if equal)
.ifne (if not equal)
.iflt (if less than)
.ifle (if less than or equal)
.ifgt (if greater than)
.ifge (if greater than or equal)
The following directives identify the different sections of an assembly file:
.text
Specifies an executable code section. This must be in front of the actual code in a file.
.data
Specifies an initialized read-write data section.
.rodata
Specifies an initialized read-only data section.
.bss
Specifies an uninitialized read-write data section.
.sdata
Specifies a small data section as initialized and read-write.
.sdata2
Specifies a small data section as initialized and read-only.
.sbss
Specifies a small data section as uninitialized and read-write.
.debug
Specifies a debug section. If you enable the debugger, the assembler automatically generates some debug information for your project. However, you use special directives in the debug section that provide the debugger with more detailed information. For more information on the debug directives, see "Debugging Directives."
.previous
Reverts to the previous section. This switch toggles between the current section and the previous section.
.offset [expression]
Defines a record. The optional parameter expression specifies the initial location counter. The record definition extends until the start of the next section.
Within a record, you can use only the following directives:
.equ |
.set |
.textequ |
.align |
.org |
.space |
.byte |
.short |
.long |
.space |
.ascii |
.asciz |
.float |
.double |
The data declaration directives (like .byte and .short) update the location counter but do not allocate any storage.
Listing 3.1 shows a sample record definition.
A record definition with the offset directive:
.offset top: .short 0 left: .short 0 bottom: .short 0 right: .short 0 rectSize .equ *
For the ELF (Executable and Linkable Format) object file format, the .section directive has the following syntax:
.section name [ ,alignment ] [ ,type ] [ ,flags ]
Defines a section in an object file. Use this directive to create arbitrary relocatable sections, including sections to be loaded at an absolute address.
Table 3.1 describes the syntax elements for the ELF .section directive.
Syntax descriptions for ELF .section directive:
| Syntax Element |
Description |
|---|---|
|
|
|
The following example specifies a section named vector with an alignment of 4 bytes:
.section vector,4
Table 3.2 defines the ELF section types.
| Type |
Name |
Description |
|---|---|---|
Table 3.3 defines the ELF section flags.
| Flag |
Name |
Description |
|---|---|---|
The assembler provides the following directives that let you import and export labels:
For more information on labels, see "Labels".
NOTE You cannot import or export equates or local labels.
.global label [ ,label ]
Instructs the assembler to export the specified labels, that is, make them available to other files.
Use the .extern or .public directive to reference the labels in another file.
.extern label [ ,label ]
Instructs the assembler to import the specified labels, that is, to find the label definitions in another file.
Use the .global or .public directive to export the labels from another file.
.public label [ ,label ]
Declares that the specified labels are public. If the labels are already defined in the same file, the assembler exports them, that is, makes them available to other files. If the equates are not already defined, the assembler imports them, that is, finds the label definitions in another file.
You can use the following directives to create equates:
equate .set expression
Temporarily assigns the value expression to equate. You can change the value of equate after defining it.
equate = expression
Temporarily assigns the value expression to equate. You can change the value of equate after defining it.
NOTE This directive is equivalent to .set and is available only for compatibility with assemblers provided by other companies.
equate .equ expression
Permanently assigns the value expression to equate. You cannot change the value of equate after defining it.
equate .textequ "string"
Substitutes equate with the text you specify in string. You can use this directive, which helps to port existing code, to give new names to machine instructions, directives, and operands.
Whenever you use equate, the assembler replaces it with string before performing any other processing on that source line. Listing 3.2 shows examples of .textequ statements.
textequ examples:
dc.b .textequ ".byte" endc .textequ ".endif"
The assembler provides the following types of directives that initialize data:
The following directives initialize blocks of integer data:
[ label ] .byte expression [ ,expression ]
Declares an initialized block of bytes with the name label. The assembler allocates one byte for each expression. Each expression must fit in a byte.
[ label ] .short expression [ ,expression ]
Declares an initialized block of 16-bit short integers with the name label. The assembler allocates 16 bits for each expression. Each expression must fit in 16 bits.
[ label ] .long expression [ ,expression ]
Declares an initialized block of 32-bit short integers with the name label. The assembler allocates 32 bits for each expression. Each expression must fit in 32 bits.
[ label ] .space expression
Declares a block of zero-initialized bytes with the name label. The assembler allocates a block expression bytes long and initializes each byte to zero.
[ label ] .fill expression
Declares a block of zero-initialized bytes with the name label. The assembler allocates a block expression bytes long and initializes each byte to zero.
The following directives initialize blocks of character data:
A string can contain any of the escape sequences shown in Table 3.4.
| Sequence |
Description |
|---|---|
| \b | |
| \n | |
| \r | |
| \t | |
| \" | |
| \\ | |
| \nnn |
[ label ] .ascii "string"
Declares a block of storage for the string string with the name label. The assembler allocates a byte for each character in string.
[ label ] .asciz "string"
Declares a zero-terminated block of storage for the string string with the name label. The assembler allocates a byte for each character in string. The assembler then allocates an extra byte at the end and initializes the byte to zero.
The following directives initialize blocks of floating-point data:
[ label ] .float value [ ,value ]
Declares an initialized block of 32-bit floating-point numbers with the name label. The assembler allocates 32 bits for each value value. Each value must fit in the specified size.
[ label ] .double value [ ,value ]
Declares an initialized block of 64-bit floating-point numbers with the name label. The assembler allocates 64 bits for each value value. Each value must fit in the specified size.
These directives let you control how the assembler emits code:
.align expression
Aligns the location counter to the next multiple of the expression. The expression must be a power of 2, such as 2, 4, 8, 16, or 32.
.endian big | little
Specifies the byte ordering for the target processor.
NOTE You can use this directive only for processors that allow you to change the byte ordering.
.error "error"
Prints error to the Errors & Warnings window in the CodeWarrior IDE.
.include filename
Causes the assembler to switch input to filename. The assembler takes input from the specified file. When the assembler reaches the end of the file, it begins taking input from the assembly statement line that follows the .include directive.
The file specified by filename can contain an .include directive for another file.
.pragma pragma-type setting
Tells the assembler to assemble the code using a particular pragma setting.
.org expression
Changes the location counter to the value of expression. The addresses of the subsequent assembly statements start at the new value of the location counter. The value of expression must be greater than the current value of the location counter.
.option keyword setting
Sets the assembler options as described in Table 3.5. Specifying reset sets the option to its previous setting. Using reset a second time resets the option to the setting before the current setting.
| Keyword |
Description |
|---|---|
| alignment off | on | reset | |
| branchsize 8 | 16 | 32 | |
| case off | on | reset |
Case-sensitive identifiers checkbox of the Assembler settings panel, described in "Case-sensitive identifiers".
|
| colon off | on | reset |
Labels must end with ':' checkbox of the Assembler settings panel, described in "Labels must end with ':'".)
|
| If this option is on, the assembler does not allow macros that use $AT. If this option is off, the assembler produces a warning if a macro uses $AT. | |
| period off | on | reset |
Directives begin with '.' checkbox of the Assembler settings panel, described in "Directives begin with '.'".
|
| reorder off | on | reset |
|
| space off | on | reset |
Allow space in operand field checkbox of the Assembler settings panel, described in "Allow space in operand field".)
|
When you enable the debugger, the assembler automatically generates some debug information for your project. However, you can use the following directives in the debug section to provide the debugger with more detailed information:
NOTE The preceding directives are allowed only in the .debug and .text sections of an assembly file.
For the debugging directives to work, you must enable debugging for the particular file that contains them (in the Project window).
.file "filename"
Specifies the name of the file containing the source code. This directive allows generated assembly to be correlated with the source code.
NOTE The .file directive must precede the other debugging directives in the assembly language file.
.function "func", label, length
Specifies that the subroutine func begins at label and is length bytes long.
.line number
Specifies the absolute line number in the current source file that generated the subsequent code or data. The first line in the file is numbered 1.
.size symbol, expression
Specifies that symbol is expression bytes long.
.type symbol, type
Specifies that symbol is of type type, where type can be either @function (a function) or @object (a variable).