4 ASSEMBLY LANGUAGE

This chapter contains the following sections:

Input Specification
Assembler Significant Characters

4.1 Input Specification

An assembly program consists of zero or more statements, one statement per line. A statement may optionally be followed by a comment, which is introduced by a semicolon character (;) and terminated by the end of the input line. Any source statement can be extended to one or more lines by including the line continuation character (\) as the last character on the line to be continued. The length of a source statement (first line and any continuation lines) is only limited by the amount of available memory. Upper and lower case letters are considered equivalent for assembler mnemonics and directives, but are considered distinct for labels, symbols, directive arguments, and literal strings.

A statement can be defined as:

[label:] [instruction | directive | macro_call] [; comment]

where,

label is an identifier or number. A label does not have to start on the first position of a line, but a label must always be followed by a colon.

instruction is any valid TriCore assembly language instruction consisting of a mnemonic and operands. Operands are described in the chapter Operands and Expressions.

directive any one of the assembler directives; described separately in the chapter Assembler Directives.

macro_call a call to a previously defined macro. See the chapter Macro Operations.

A statement may be empty.

4.2 Assembler Significant Characters

There are several one character sequences that are significant to the assembler. Some have multiple meanings depending on the context in which they are used. Special characters associated with expression evaluation are described in Chapter 5 , Operands and Expressions. Other assembler-significant characters are:

Individual descriptions of each of the assembler special characters follow. They include usage guidelines, functional descriptions, and examples.

;

Comment Delimiter Character

Any number or characters preceded by a semicolon (;), but not part of a literal string, is considered a comment. Comments are not significant to the assembler, but they can be used to document the source program. Comments will be reproduced in the assembler output listing. Comments are preserved in macro definitions.

Comments can occupy an entire line, or can be placed after the last assembler-significant field in a source statement. The comment is literally reproduced in the listing file.

Examples:

; This comment begins in column 1 of the source file
Loop: CALL COMPUTE ; This is a trailing comment
                   ; These two comments are preceded
                   ; by a tab in the source file

\

Line Continuation Character or
Macro Dummy Argument Concatenation Operator

Line Continuation

The backslash character (\), if used as the last character on a line, indicates to the assembler that the source statement is continued on the following line. The continuation line will be concatenated to the previous line of the source statement, and the result will be processed by the assembler as if it were a single line source statement. The maximum source statement length (the first line and any continuation lines) is 512 characters.

Example:

; THIS COMMENT \
EXTENDS OVER \
THREE LINES

Macro Argument Concatenation

The backslash (\) is also used to cause the concatenation of a macro dummy argument with other adjacent alphanumeric characters. For the macro processor to recognize dummy arguments, they must normally be separated from other alphanumeric characters by a non-symbol character. However, sometimes it is desirable to concatenate the argument characters with other characters. If an argument is to be concatenated in front of or behind some other symbol characters, then it must be followed by or preceded by the backslash, respectively.

See also section 6.5.1 .

Example:

Suppose the source input file contained the following macro definition:

SWAP_MEM .macro REG1,REG2         ;swap memory contents
     LD.W D0,[A\REG1]              ;using D0 as temp
     LD.W D1,[A\REG2]              ;using D1 as temp
     ST.W [A\REG1],D1
     ST.W [A\REG2],D0
     .endm

The concatenation operator (\) indicates to the macro processor that the substitution characters for the dummy arguments are to be concatenated in both cases with the character A. If this macro were called with the following statement,

     SWAP_MEM 0,1

the resulting expansion would be:

     LD.W  D0,[A0]
     LD.W  D1,[A1]
     ST.W  [A0],D1
     ST.W  [A1],D0

?

Return Value of Symbol Character

The ?symbol sequence, when used in macro definitions, will be replaced by an ASCII string representing the value of symbol. This operator may be used in association with the backslash (\) operator. The value of symbol must be an integer.

See also section 6.5.2 .

Example:

Consider the following macro definition:

SWAP_MEM .macro REG1,REG2     ;swap memory contents
     LD.W D0,_lab\?REG1        ;using D0 as temp
     LD.W D1,_lab\?REG2        ;using D1 as temp
     ST.W _lab\?REG1,D1
     ST.W _lab\?REG2,D0
     .endm

If the source file contained the following .SET statements and macro call,

AREG .set  1
BREG .set  2
     SWAP_MEM  AREG,BREG

the resulting expansion as it would appear on the source listing would be:

     LD.W  D0,_lab1
     LD.W  D1,_lab2
     ST.W  _lab1,D1
     ST.W  _lab2,D0

%

Return Hex Value of Symbol Character

The %symbol sequence, when used in macro definitions, will be replaced by an ASCII string representing the hexadecimal value of symbol. This operator may be used in associations with the backslash (\) operator. The value of symbol must be an integer.

See also section 6.5.3 .

Example:

Consider the following macro definition:

GEN_LAB   .macro LAB,VAL,STMT
LAB\%VAL: STMT
     .endm

If this macro were called as follows,

NUM .set     10
     GEN_LAB HEX,NUM,'NOP'

The resulting expansion as it would appear in the listing file would be:

HEXA: NOP

^

Macro Local Label Character

The circumflex (^), when used as a unary operator in a macro expansion, will cause name mangling of any associated local label. Normally, the macro preprocessor will leave any local label inside a macro expansion to a normal label in the current module. By using the Local Label character (^), the label is made a unique label. This is done by removing the leading underscore and appending a unique string "__M_Lxxxxxx" where "xxxxxx" is a unique sequence number. The ^-operator has no effect outside of a macro expansion. The ^-operator is useful for passing label names as macro arguments to be used as local label names in the macro. Note that the circumflex is also used as the binary exclusive or operator.

See also section 6.5.5 .

Example:

Consider the following macro definition:

LOAD .macro  ADDR
      ADDR:
          LD.W  D0,ADDR
      ^ADDR:
          LD.W  D0,^ADDR
      .endm

If this macro were called as follows,

     LOAD  _LOCAL

the resulting expansion as it would appear in the listing file would be:

_LOCAL:
     LD.W  D0,_LOCAL
_LOCAL__M_L000001:
     LD.W  D0,_LOCAL__M_L000001

"

Macro String Delimiter or
Quoted String .DEFINE Expansion Character

Macro String

The double quote ("), when used in macro definitions, is transformed by the macro processor into the string delimiter, the single quote ('). The macro processor examines the characters between the double quotes for any macro arguments. This mechanism allows the use of macro arguments as literal strings.

See also section 6.5.4 .

Example:

Using the following macro definition,

CSTR .macro  STRING
     .ascii   "STRING"
     .endm

and a macro call,

     CSTR     ABCD

the resulting macro expansion would be:

     .ascii   'ABCD'

Quoted String DEFINE Expansion

A sequence of characters which matches a symbol created with a .DEFINE directive will not be expanded if the character sequence is contained within a quoted string. Assembler strings generally are enclosed in single quotes ('). If the string is enclosed in double quotes (") then .DEFINE symbols will be expanded within the string. In all other respects usage of double quotes is equivalent to that of single quotes.

Example:

Consider the source fragment below:

     .define LONG 'short'
STR_MAC .macro STRING
     .message     'This is a LONG STRING'
     .message     "This is a LONG STRING"
     .endm

If this macro were invoked as follows,

     STR_MAC   sentence

then the resulting expansion would be:

     .message     'This is a LONG STRING'
     .message     'This is a short sentence'

@

Function Delimiter

All assembler built-in functions start with the @ symbol. See section 5.4 for a full discussion of these functions.

Example:

SVAL .equ @ABS(VAL)     ; Obtain absolute value

*

Location Counter Substitution

When used as an operand in an expression, the asterisk represents the current integer value of the run-time location counter.

Example:

     .sdecL  ".CODE", CODE  AT 0x100
     .sect   ".CODE"
XBASE .equ *+0x20        ; XBASE = 0x120

Copyright © 2002 Altium BV