5 OPERANDS AND EXPRESSIONS

This chapter contains the following sections:

Operands
TriCore Addressing Modes
PCP Addressing Modes

Expressions
Number
Expression String
Symbol
Expression Type

Operators
Addition and Subtraction
Sign Operators
Multiplication and Division
Shift Operators
Relational Operators
Bitwise Operators
Logical Operators

Functions
Mathematical Functions
String Functions
Macro Functions
Assembler Mode Functions
Address Calculation Functions
Fractional Functions
Detailed Description

5.1 Operands

An operand is the part of the instruction that follows the instruction opcode. There can be one or two or even no operands in an instruction. An operand of an assembly instruction has one of the following types:

Operands Description

expr any valid expression as described in the section 5.2, Expressions.

reg any valid register.

symbol a symbolic name as created by an equate. A symbol can be an expression or a register name.

address a combination of expr, reg and symbol.

label a label reference as described in the section 4.1, Input Specification.

If an expression can be completely evaluated at assembly time, it is called an absolute expression; if it is not, it is called a relocatable expression.

See the section 5.2 , Expressions, for more details.

5.1.1 TriCore Addressing Modes

The TriCore assembly language has several addressing modes. These are listed below with a short description. For details see the TriCore CPU Manual.

Absolute

The instruction uses an 18-bit constant as the memory address. The full 32-bit address results from moving the most significant 4 bits of the 18-bit constant to the most significant bits of the 32-bit address. The other bits are zero filled.

Syntax:

constant18

Base+offset

The effective address is the sum of an address register and the sign-extended 10-bit or 16-bit offset.

Syntax:

[An]offset10
[An]offset16

Pre-increment

This addressing mode uses the sum of the address register and the offset both as the effective address and as the value written back into the address register.

Syntax:

[+An]offset10

Post-increment

This addressing mode uses the value of the address register as the effective address, and then updates this register by adding the sign-extended 10-bit offset to its previous value. Post-decrement is obtained by using a negative offset.

Syntax:

[An+]offset10

Circular

This addressing mode is used for accessing data values in circular buffers. It uses an address register pair to hold the state it requires. The even register is always a base address (B). The most-significant half of the odd register is the buffer size (L). The least significant half holds the index into the buffer (I). The effective address is (B+I). The buffer occupies memory from addresses B to B+L-1. The 10-bit offset is specified in the instruction word and is a byte-offset that can be either positive or negative.

Syntax:

[An+c]offset10

Bit-reverse

Bit reverse addressing is used to access arrays used in FFT algorithms. Bit-reverse addressing uses an address register pair to hold the required state. The even register is the base address of the array (B), the least-significant half of the odd register is the index into the array (I), and the most-significant half is the modifier (M) which is added to I after every access. The effective address is B+reverse(I). The reverse() function exchanges bit n with bit (15-n) for n = 0, ..., 7. The index, I, is post-incremented and its new value is (I + M), where M is the most significant half of the odd register.

Syntax:

[An+r]

5.1.2 PCP Addressing Modes

The PCP assembly language has several addressing modes. These addressing modes are used for FPI addressing, PRAM data indirect addressing or flow control destination addressing. For details see the PCP/DMA Architecture manual from Siemens.

5.2 Expressions

An operand of an assembler instruction or directive is either an assembler symbol, a register name or an expression. An expression is a sequence of symbols that denotes an address in a particular memory space or a number.

Expressions that can be evaluated at assembly time are called absolute expressions. Expressions where the result is unknown until all sections have been combined and located are called relocatable expressions. When any operand of an expression is relocatable the entire expression is relocatable. Relocatable expressions are emitted in the object file and evaluated by the linker or the locator. Relocatable expressions may only contain integral functions. An error is emitted when during object creation non-IEEE relocatable expressions are found.

An expression has a type which depends on the type of the identifiers in the expression. See section 5.2.4, Expression Type, for details.

The assembler evaluates expressions with 64-bit precision in two's complement.

The syntax of an expression can be any of the following:

- number

- expression_string

- symbol

- expression binary_operator expression

- unary_operator expression

- ( expression )

- function

All types of expressions are explained below and in the following sections.

( ) You can use parentheses to control the evaluation order of the operators. What is between parentheses is evaluated first.

Examples:

(3+4)*5    ; Result is 35.
           ; 3 + 4 is evaluated first.
3+(4*5)    ; Result is 23.
           ; 4 * 5 is evaluated first.
           ; parentheses are superfluous
           ; here

5.2.1 Number

Numeric constants can be used in expressions. If there is no prefix, the assembler assumes the number is decimal.

number can be one of the following:
- 0Bbin_num
- dec_num
- 0Xhex_num

Lowercase equivalences are allowed: 0b, 0x.

bin_num is a binary number formed of '0'-'1' starting with '0B' or '0b'.

dec_num is a decimal number formed of '0'-'9'.

hex_num is a hexadecimal number formed of the characters '0'-'9' and 'a'-'f' or 'A'-'F' starting with a '0X' or '0x'.

5.2.2 Expression String

An expression_string is a string with an arbitrary length evaluating to a number. The value of the string is calculated by taking the first 4 characters padded with 0 to the left.

string is a string of ASCII characters, enclosed in single (') or double (") quotes. The starting and closing quote must be the same. To include the enclosing quote in the string, double it. E.g. the string containing both quotes can be denoted as: " ' "" " or ' ' ' " '.
See the chapter Macro Operations for the differences between single and double quoted strings.

Examples:

'A'+1      ; a 1-character ASCII string,
           ; result 0x42
"9C"+1     ; a 2-character ASCII string,
           ; result 0x3944

5.2.3 Symbol

A symbol is an identifier. A symbol represents the value of an identifier which is already defined, or will be defined in the current source module by means of a label declaration or an equate directive.

Examples:

CON1 .EQU 3         ; The variable CON1 represents
                    ; the value of 3

LD.W D0,CON1+20     ; Load D0 with contents of
                    ; address 23

When you invoke the assembler, one of the following predefined symbol exists:

_ASPCP contains a string with the name of the assembler ("aspcp")

_ASTRI contains a string with the name of the assembler ("astri")

5.2.4 Expression Type

The type of an expression is either a number (integral) or an address. The result type of an expression depends on the operator and its operands. The tables below summarize all available operators.

Please note:

1. a label is of type 'address'; an equate symbol has the type of the equate expression; see section 4.1, Input Specification, for a description of labels.

2. the type of an untyped symbol can be an address or a number, depending on the context; the result of the operation can be determined using the tables;

3. the binary logical and relational operators (||, &&, ==, !=, <, <=, >, >=) accept any combination of operands, the result is always the integral number 0 or 1;

4. the binary shift and bitwise operators <<, >>, |, & and ^ only accept integral operands.

The following table shows the result type of expressions with unary operators (a '*' indicates an illegal combination).

Operator integer addr
~ integer *
! integer *
- integer *
+ integer integer

Table 5-1: Expression type, unary operators

The following table shows the result type of expressions with binary numerical operators.

Operator integer, integer addr, integer integer, addr addr,addr
- integer addr * integer
+ integer addr addr *
* integer * * *
/ integer * * *
% integer * * *

Table 5-2: Expression type, binary numerical operators

a string operand will be converted to an integral number

The following table shows the result type of functions. A '-' in the column Operands means that the function has no operands.

Function Operands Result
@ABS() integer integer
@ARG() symbol
integer
integer
integer
@ASPCP() - string
@ASTRI() - string
@CAT() string,string string
@CNT() - integer
@DEF() symbol integer
@HI() integer integer
@HIS() integer integer
@LEN() string integer
@LO() integer integer
@LOS() integer integer
@LST() - integer
@MAC() symbol integer
@MAX() integer,integer,... integer
@MIN() integer,integer,... integer
@MXP() - integer
@POS() string,string
string,string,integer
integer
integer
@SCP() string,string integer
@SGN() integer integer
@SUB() string,integer,integer string

Table 5-3: Expression type, functions

5.3 Opera tors

There are two types of operators:

- unary operators

- binary operators

Operators can be arithmetic operators, shift operators, relational operators, bitwise operators, or logical operators. All operators are described in the following sections.

If the grouping of the operators is not specified with parentheses, the operator precedence is used to determine evaluation order. Every operator has a precedence level associated with it. The following table lists the operators and their order of precedence (in descending order).

Operators Type
+, -, ~, ! unary
*, /, % binary
+, - binary
<<, >> binary
<, <=, >, >= unary
==, != binary
& binary
^ binary
| binary
&& binary
|| binary

Table 5-4: Operators Precedence List

Except for the unary operators, the assembler evaluates expressions with operators of the same precedence level left-to-right. The unary operators are evaluated right-to-left . So, -4 + 3 * 2 evaluates to (-4) + (3 * 2).

5.3.1 Addition and Subtraction

Synopsis:

Addition: operand + operand

Subtraction: operand - operand

The + operator adds its two operands and the - operator subtracts them. The operands can be any expression evaluating to an absolute number or a relocatable operand, with the restrictions of Table 5-2 .

Examples:

0xA342  + 23        ; addition of absolute numbers
0xFF1A  - AVAR      ; subtraction with the value of
                    ; symbol AVAR

5.3.2 Sign Operators

Synopsis:

Plus: +operand
Minus: -operand

The + operator does not modify its operand. The - operator subtracts its operand from zero. See also the restrictions in Table 5-1 .

Example:

5+-3      ; result is 2

5.3.3 Multiplication and Division

Synopsis:

Multiplication: operand * operand
Division: operand / operand
Modulo: operand % operand

The * operator multiplies its two operands, the / operator performs an integer division, discarding any remainder. The % operator also performs an integer division, but discards the quotient and returns the remainder. The operands can be any expression evaluating to an absolute number or a relocatable operand, with the restrictions of Table 5-2 . Note that the right operands of the / and % operator may not be zero.

Examples:

AVAR*2         ; multiplication
0xFF3C/COUNT   ; division
23%4           ; modulo, result is 3

5.3.4 Shift Operators

Synopsis:

Shift left: operand << count
Shift right: operand >> count

These operators shift their left operand (operand) either left (<<) or right (>>) by the number of bits (absolute number) specified with the right operand (count). The operands can be any expression evaluating to an (integer) number.

Examples:

AVAR>>4     ; shift right variable AVAR, 4 times

5.3.5 Relational Operators

Synopsis:

Equal: operand == operand
Not equal: operand != operand
Less than: operand < operand
Less than or equal: operand <= operand
Greater than: operand > operand
Greater than or equal: operand >= operand

These operators compare their operands and return an absolute number (an integer) of 1 for `true' and 0 for `false'. The operands can be any expression evaluating to an absolute number or a relocatable operand.

Examples:

3>=4        ; result is 0 (false)
4==COUNT    ; 1 (true), if COUNT is 4.
            ; 0 otherwise.
9<10        ; result is 1 (true)

5.3.6 Bitwise Operators

Synopsis:

Bitwise AND: operand & operand
Bitwise OR: operand | operand
Bitwise XOR: operand ^ operand
One's complement ~ operand

The AND, OR and XOR operators take the bitwise AND, OR respectively XOR of the left and right operand. The one's complement (bitwise NOT) operator performs a bitwise complement on its operand. The operands can be any expression evaluating to an (integer) number.

Examples:

0BH&3  ; result is 3
          0B1011
          0B0011 &
          0B0011

~0xA   ; result is 0xFFF5
          ~ 0B0000000000001010
          = 0B1111111111110101

5.3.7 Logical Operators

Synopsis:

Logical AND: operand && operand
Logical OR: operand || operand
Logical NOT: ! operand

The logical AND operator returns an integer 1 if both operands are non-zero; otherwise it returns an integer 0. The logical OR operator returns an integer 1 if either of its operands is non-zero; otherwise it returns an integer 0. The ! operator performs a logical not on its operand. ! returns an integer 1 (`true) if the operand is 0; otherwise, ! returns 0 (`false'). The operands can be can be any expression evaluating to an integer.

Examples:

0xB&&3     ; result is 1 (true)

!0xA       ; result is 0 (false)
!(4<3)     ; result is 1 (true)
           ; 4 < 3 result is 0 (false)

5.4 Functions

The assembler has several built-in functions to support data conversion, string comparison, and math computations. Functions can be used as terms in any arbitrary expression. Functions have the following syntax:

Functions start with the '@' sign and have zero or more arguments, and are always followed by opening and closing parentheses. There must be no intervening spaces between the function name and the opening parenthesis and between the (comma-separated) arguments.

Assembler functions can be grouped into four types:

1. Mathematical functions

2. String functions

3. Macro functions

4. Assembler mode functions

5. Address calculation functions

6. Fractional functions

5.4.1 Mathematical Functions

The mathematical functions comprise min/max functions, among others:

ABS - Absolute value

MAX - Maximum value

MIN - Minimum value

SGN - Return sign

5.4.2 String Functions

String functions compare strings, return the length of a string, and return the position of a substring within a string:

CAT - Catenate strings

LEN - Length of string

POS - Position of substring in string

SCP - Compare strings

SUB - Substring from a string

5.4.3 Macro Functions

Macro functions return information about macros:

ARG - Macro argument function

CNT - Macro argument count

MAC - Macro definition function

MXP - Macro expansion function

5.4.4 Assembler Mode Functions

Miscellaneous functions having to do with assembler operation:

ASPCP - Assembler executable name (aspcp only)

ASTRI - Assembler executable name (astri only)

DEF - Symbol definition function

LST - LIST control flag value

5.4.5 Address Calculation Functions

Functions that are used to calculate the high and low parts of an address:

LO - Lower 16 bits of an address

HI - Upper 16 bits of an address

LOS - Lower 16 bits of an address with adjustment for signed addition

HIS - Upper 16 bits of an address with adjustment for signed addition

5.4.6 Fractional Functions

Functions that are used to return the fractional representation of an expression:

FRACT - Return 32-bit fract

SFRACT - Return 16-bit fract

5.4.7 Detailed Description

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

@ABS(expression)

Returns the absolute value of expression as an integer value.

Example:

@ARG(symbol | expression)

Returns integer 1 if the macro argument represented by symbol or expression is present, 0 otherwise. If the argument is a symbol it must be single-quoted and refer to a dummy argument name. If the argument is an expression it refers to the ordinal position of the argument in the macro dummy argument list. A warning will be issued if this function is used when no macro expansion is active.

Example:

@ASPCP()

Returns the name of the assembler executable. This is aspcp for the PCP assembler.

Example:

@ASTRI()

Returns the name of the assembler executable. This is astri for the TriCore assembler.

Example:

@CAT(str1,str2)

Concatenates the two strings into one string. The two strings must be enclosed with single or double quotes.

Example:

@CNT()

Returns the count of the current macro expansion arguments as an integer. A warning will be issued if this function is used when no macro expansion is active.

Example:

@DEF(symbol)

Returns an integer 1 if symbol has been defined, 0 otherwise. symbol may be any label not associated with a .MACRO directive. If symbol is quoted it is looked up as a .DEFINE symbol; if it is not quoted it is looked up as an ordinary label.

Example:

@FRACT(expression)

This function returns the 32-bit fractional representation (Q31) of the floating point expression. The expression must be in the range [-1,+1>.

Example:

@HI(expression)

Returns the upper 16 bits of a value. @HI(expr ) is equivalent to ((expr >> 16) & 0xffff).

Example:

@HIS(expression)

Returns the upper 16 bits of a value, adjusted for a signed addition of the lower 16 bits. @HIS(expr) is equivalent to (((expr + 0x800) >> 16) & 0xffff).

Example:

@LEN(string)

Returns the length of string as an integer.

Example:

@LO(expression)

Returns the lower 16 bits of a value. @LO(expr ) is equivalent to (expr & 0xffff).

Example:

@LOS(expression)

Returns the lower 16 bits of a value, adjusted for a signed addition. @LOS(expr) is equivalent to (((expr + 0x8000) & 0xffff) - 0x8000).

Example:

@LST()

Returns the value of the LIST control flag as an integer. Whenever a LIST ON control is encountered in the assembler source, the flag is incremented; when a LIST OFF control is encountered, the flag is decremented.

Example:

@MAC(symbol)

Returns an integer 1 if symbol has been defined as a macro name, 0 otherwise.

Example:

@MAX(expr1[,exprN]...)

Returns the greatest of expr1,...,exprN as an integer.

Example:

@MIN(expr1[,exprN]...)

Returns the least of expr1,...,exprN as an integer.

Example:

@MXP()

Returns an integer 1 if the assembler is expanding a macro, 0 otherwise.

Example:

@POS(str1,str2[,start])

Returns the position str2 in str1 as an integer, starting at position start. If start is not given the search begins at the beginning of str1. If the start argument is specified it must be a positive integer and cannot exceed the length of the source string.

Example:

@SCP(str1,str2)

Returns an integer 1 if the two strings compare, 0 otherwise. The two strings must be separated by a comma.

Example:

@SFRACT(expression)

This function returns the 16-bit fractional representation (Q15) of the floating point expression. The expression must be in the range [-1,+1>.

Example:

@SGN(expression)

Returns the sign of expression as an integer: -1 if the argument is negative, 0 if zero, 1 if positive. The expression may be relative or absolute.

Example:

@SUB(str,expr1,expr2)

Returns the substring from str as a string. expr1 is the starting position within str and expr2 is the length of the desired string. The assembler issues an error if either expr1 or expr2 exceeds the length of str.

Example:


Copyright © 2002 Altium BV