This chapter describes the syntax of assembly language statements.
This chapter includes the following topics:
Three types of assembly language statements exist:
The type of the assembly language statement differs depending on whether the operation performed by the statement is a machine instruction, a macro call, or an assembler directive.
Instruction, directive, and macro names are case insensitive. For example, MOV, Mov, and mov all name the same instruction.
When creating assembly language statements, you must be aware of the following information:
The maximum length of a statement or an expanded macro is 1000 characters. A statement must reside on a single line. However, you can concatenate two or more lines by typing a backslash (\) character at the end of the line. Each line of the source file can contain only one statement unless the assembler is running in GNU mode, which allows multiple statements to reside on one line, separated by semicolons.
For information on where to find machine instructions for a particular chip, see the processor-specific chapters of this manual. For more information on assembler directives, see "Using Directives". For more information on macros, see "Using Macros".
Listing 2.1 shows the syntax of an assembly language statement.
statement ::= [ symbol ] operation [ operand ] [ ,operand ]... [ comment ] operation ::= machine_instruction | assembler_directive | macro_call operand ::= symbol | constant | expression | register_name
Table 2.1 provides information related to the syntax shown in Listing 2.1.
| Syntax Element |
Description |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
A symbol is a group of characters that represents a value, such as an address, numeric constant, string constant, or character constant. The length of a symbol name is unlimited.
The syntax of a symbol follows:
NOTE For the complete syntax of an assembly language statement, see Listing 2.1.
In general, a symbol has file-wide scope. File-wide scope means that you can access the symbol anywhere within the file where you defined the symbol and only within that file. However, symbols sometimes have a different scope. For more information, see "Local labels".
This section discusses the following topics:
A label is a symbol that represents an address. The assembler provides local labels and non-local labels. Whether a label is local or non-local determines its scope.
The syntax of a label follows:
label ::= local_label [ : ] | non-local_label[ : ]
NOTE For the complete syntax of an assembly language statement, see Listing 2.1.
By default, a label ends with a colon (:) and can begin in any column. However, if you are porting existing code that does not follow this convention, clear the Labels must end with ':' checkbox on the Assembler settings panel. After you clear the checkbox, a label must either begin in column 1 or end with a colon (:).
NOTE For more information, see "Common Assembler Settings".
This section contains the following topics:
A non-local label is a symbol that represents an address and has file-wide scope.
The first character of a non-local label must be one of the following:
The subsequent characters of a non-local label can be either a character from the preceding list or one of the following:
A numeral between zero and nine (0-9) A dollar sign ($)
A local label is a symbol that represents an address and has local scope. Local scope means that the scope of the label extends forward and backward within the file until the point where the assembler encounters a non-local label.
The first character of a local label must be an at-sign (@). The subsequent characters of a local label must be one of the following:
NOTE: You cannot export local labels. In addition, local labels do not appear in debugging tables.
Within an expanded macro, the scope of local labels works differently:
Listing 2.2 shows the scope of local labels in macros.
The scope of local labels in a macro:
MAKEPOS .MACRO cmp eax, 1 jne @SKIP neg eax @SKIP: ;Scope of this label is within the macro .ENDM START: mov eax, COUNT cmp eax, 1 jne @SKIP MAKEPOS @SKIP: ;Scope of this label is START to END ;excluding lines arising from ;macro expansion add eax, 1 END: ret
In Listing 2.2, the @SKIP label defined in the macro does not conflict with the @SKIP label defined in the main body of code.
The assembler assumes a flat 32-bit memory space. You can specify the relocation of a 32-bit label with the expressions shown in Table 2.2.
NOTE Some expressions are not allowed in all assemblers.
| This |
Represents this |
|---|---|
| label | |
| label@l | |
| label@h | |
| label@ha | |
| label@sdax | |
| label@got |
An equate is a symbol that represents any value. You can create an equate with a .equ or .set directive.
NOTE For more information, see "equ" and "set".
This section contains the following topics:
The first character of an must be one of the following:
The subsequent characters of an equate can be either a character from the preceding list or one of the following:
A numeral between zero and nine (0-9) A dollar sign ($)
The assembler allows forward equates. This means that you can refer to an equate in a file before it is defined. When an assembler encounters an expression it cannot resolve because the expression references a symbol whose value is not known, the assembler retains the expression and marks it as unresolved. After the assembler reads the entire file, it reevaluates unresolved expressions and, if necessary, repeatedly reevaluates them until it resolves them all or it cannot resolve them any further. If the assembler cannot resolve an expression, it raises an error.
However, the assembler must be able to immediately resolve any expression whose value affects the location counter.
NOTE Note that if the assembler can make a reasonable assumption about the location counter, the expression is allowed. For example, in a forward branch instruction for a 68K processor, you can specify a default assumption of 8, 16, or 32 bits.
Thus, the code in Listing 2.3 is valid.
.long alloc_size alloc_size .set rec_size + 4 ; a valid forward equate on next line rec_size .set table_start-table_end ;... table_start: ; ... table_end:
However, the code in Listing 2.4 is not valid. The assembler cannot immediately resolve the expression in the .space directive. Consequently, the effect on the location counter is unknown.
;invalid forward equate on next line rec_size .set table_start-table_end .space rec_size ; ... table_start: ; ... table_end:
The Case-sensitive identifiers checkbox on the Assembler settings panel lets you choose whether symbols are case-sensitive. If you click the checkbox, symbols are case sensitive, so SYM1, sym1, and Sym1 are three different symbols, for example. If you clear the checkbox, symbols are not case-sensitive, so SYM1, sym1, and Sym1 are the same symbol, for example. By default, this option is on.
The assembler recognizes three kinds of constants:
Table 2.3 lists the preferred notation for integer constants.
Preferred integer constant notation:
| For numbers of this type |
Use |
|---|---|
To help you port existing code, the assembler also supports the notation in Table 2.4.
Alternate integer constant notation:
| For numbers of this type |
Use |
|---|---|
| Hexadecimal | |
| Hexadecimal | |
| Decimal | |
| Binary |
NOTE The assembler stores and manipulates integer constants using 32-bit signed arithmetic.
You can specify floating point constants in either hexadecimal or decimal format. A floating point constant in decimal format must contain either a decimal point or an exponent, e.g. 1E-10 or 1.0.
You can use floating point constants only in data generation directives like .float and .double, or in floating point instructions. You cannot use them in expressions.
Enclose a character constant in single quotes unless the character constant includes a single quote. In that case, enclose the character constant in double quotes.
NOTE A character constant cannot include both single and double quotes.
The maximum width of a character constant is 4 characters, depending on the context. For example, the following items are character constants:
A character constant can contain any of the escape sequences shown in Table 2.5.
| Sequence |
Description |
|---|---|
| \b | |
| \n | |
| \r | |
| \t | |
| \" | |
| \\ | |
| \nnn |
A character constant is zero-extended to 32 bits during computation. You can use a character constant anywhere you can use an integer constant.
The assembler evaluates expressions using 32-bit signed arithmetic and does not check for arithmetic overflow.
Since there is no common set of operators in the existing assemblers for different processors, the assembler uses an expression syntax similar to the one for the C language. Expressions use the C language arithmetic rules for such things as parentheses and associativity, and they use the same operators.
NOTE To refer to the program counter in an expression, use a period (.), dollar sign ($), or asterisk (*).
The assembler supports the binary operators listed in Table 2.6.
| Operator |
Description |
|---|---|
| + | |
| - | |
| * | |
| / | |
| % | |
| || | |
| && | |
| | | |
| & | |
| ^ | |
| << | |
| >> | |
| == | |
| != | |
| <= | |
| >= | |
| < | |
| > |
The assembler supports the unary operators listed in Table 2.7.
| Operator |
Description |
|---|---|
| + | |
| - | |
| ~ |
The assembler also supports the operations listed in Table 2.8.
| Operator |
Description |
|---|---|
| <> | |
| // | |
| ! | |
| !! |
The operators have the following precedence, with the highest priority first:
Comments are text that the assembler ignores. You can use them to document your code.
There are several ways you can specify comments:
/* This is a comment. */ // This is a comment.
NOTE The asterisk (*) must be the first character of the line for it to specify a comment. The asterisk has other meanings when it occurs elsewhere in a line.
Allow space in operand field checkbox on the Assembler settings panel. In this case, the assembler ignores any text between a space character in the operand field and the end of the line. Therefore, after you type a space in the operand field, you can type a comment on the remainder of the line.
# This is a comment.
NOTE The assembler distinguishes between a comment that begins with a pound sign (#) and a preprocessor directive that begins with a pound sign.
The three immediately preceding comment methods are helpful for porting existing code.
By default, the assembler aligns all data on a natural boundary for the data size and for the target processor family. You can turn off alignment with the alignment argument to the .option directive, described in "option."
The assembler does not align data automatically in the .debug section. For more information on the .debug section, see "Debugging Directives."