5 OPERANDS AND EXPRESSIONS

This chapter contains the following sections:

Operands
Operands and Addressing Modes

Expressions
Number
Expression String
Symbol
Expression Type
Memory Spaces

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

Functions
Mathematical Functions
Conversion Functions
String Functions
Macro Functions
Assembler Mode Functions
Detailed Description

5.1 Operands

An operand is the part of the instruction that follows the instruction opcode. There can be one, two, three 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 Expressions.

reg any valid register as described in the section Registers.

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

address a combination of expr, reg and symbol.

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 Operands and Addressing Modes

The DSP56xxx assembly language has several addressing modes. These are listed below with a short description. For details see the DSP56000, DSP56300 and DSP56600 Family Manuals.

Register Direct

The instruction specifies the register which contains the operand.

Syntax:

mnemonic register

Address Register Indirect

The instruction specifies the register containing the operand address. Several forms are available.

Syntax:

mnemonic (Rn)
mnemonic (Rn)+
mnemonic (Rn)-
mnemonic (Rn)+Nn
mnemonic (Rn)-Nn
mnemonic (Rn+Nn)
mnemonic -(Rn)
mnemonic (Rn+displ) (not for DSP5600x )

Immediate

An immediate operand is a one word number or short number, which is encoded as part of the instruction. Immediate operands are indicated by the # sign before the expression defining the value of the operand.

Syntax:

mnemonic #number

Absolute

The instruction contains the operand address. The address can be 16 or 24 bits (absolute address), 6 bits zero extended (absolute short) or 6 bits ones extended (I/O short).

Syntax:

mnemonic direct_address

Short Jump

The instruction contains the 12-bit address zero extended to 16 or 24 bits, which allows addresses $000-$FFF to be accessed.

Syntax:

mnemonic jump_address

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; floating point functions and numbers are not supported by the IEEE object format. 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

Spaces are not allowed inside expressions! Example: 3 + 4 is not valid, but 3+4 is.

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:
- %bin_num
- dec_num (or `dec_num)
- $hex_num
- float_num

bin_num is a binary number formed of '0'-'1' prefixed with a '%'.

dec_num is a decimal number formed of '0'-'9', optionally prefixed with a '`'.

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

float_num is a floating point number formed of '0'-'9' and indicated either by a preceding, following, or included decimal point or by the presence of 'E' or 'e'. Floating point numbers are always base 10.

A number may be written without a leading radix indicator if the input radix is changed using the RADIX directive. For example, a hexadecimal number may be written without the leading dollar sign ($) if the input radix is set to 16 (assuming an initial radix of 10). The default radix is 10.

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 $00000042
"9C"+1     ; a 2-character ASCII string,
           ; result $00003944

Two strings can be concatenated with the strings concatenation operator (++). The two strings must each be enclosed by single or double quotes, and there must be no intervening blanks between the operator and the two strings:

Square brackets ([ ]) delimit a substring operation in the form:

offset is the start position within string. length is the length of the desired substring. Both values may not exceed the size of string.

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

MOVE CON1+$20,R1  ; Move contents of address
                  ; $23 to register R1

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

_AS56 contains a string with the name of the assembler ("as56" or "as563")

5.2.4 Expression Type

The type of an expression is either a number (floating point or 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. when an illegal combination (denoted as *) is found, a warning is emitted and the expression type will be undefined;

2. a label is of type 'address'; an equate symbol has the type of the equate expression;

3. 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;

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

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

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

Operator num addr
~ num *
! num *
- num *
+ num num

Table 5-1: Expression type, unary operators

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

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

Table 5-2: Expression type, binary numerical operators

"num <op> float" and "float <op> num" evaluates to float

any combination of an address with a float is illegal

a string operand will be converted to an integral number

"addr - addr" is only valid when both addresses are in the same address space, or in compatible address spaces (see Table 5-4)

The following table shows the result type of functions. num can be float and integer. A '-' in the column Operands means that the function has no operands.

Function Operands Result
@ABS() num float
@ACS() num float
@ARG() symbol
integer
integer
integer
@AS56() - string
@ASN() num float
@AT2() num,num float
@ATN() num float
@CEL() num float
@CNT() - float
@COH() num float
@COS() num float
@CVF() num float
@CVI() num integer
@CVS() mem,expr mem:expr
@DEF() symbol integer
@DEFMEM() - string
@DSP() - integer
@FLD() num,num,num
num,num,num,num
integer
integer
@FLR() num float
@FRC() num integer
@L10() num float
@LEN() string integer
@LFR() num integer
@LNG() num,num integer
@LOG() num float
@LST() - integer
@LUN() num float
@MAC() symbol integer
@MAX() num,num,...,float,...
integer,integer,...
float
integer
@MIN() num,num,...,float,...
integer,integer,...
float
integer
@MODEL() - string
@MSP() num integer
@MXP() - integer
@POS() string,string
string,string,num
integer
integer
@POW() num,num float
@RND() - float
@RVB() num
num,num
integer
integer
@SCP() string,string integer
@SGN() num integer
@SIN() num float
@SNH() num float
@SQT() num float
@STKMEM() - string
@TAN() num float
@TNH() num float
@UNF() num float
@XPN() num float

Table 5-3: Expression type, functions

5.2.5 Memory Spaces

All addresses have a memory space attribute of either X, Y, L, Program, EMI, or Unknown, to distinguish between different address spaces. A number always has the memory attribute None. When subtracting an address from another address the address spaces are combined to form the resulting type. See the table below for legal combinations and their resulting address space. The type N stands for a number. The function @CVS() can be used to change the address space of an address or to make an address of any number. The @MSP() function can be used to extract the address space from any expression. An external symbol which is declared without a memory space can be used as an address in any memory space.

                     Left Operand Memory Space Attribute

                     N   X   Y   L   P   E

Right Operand    N   N   X   Y   L   P   E
Memory Space     X   *   N   *   N   *   *
Attribute        Y   *   *   N   N   *   *
                 L   *   N   N   N   *   *
                 P   *   *   *   *   N   *
                 E   *   *   *   *   *   N

* = Represents an illegal operation that will result in an error.

Table 5-4: Compatible memory types for binary '-' operator

Memory space attributes become important when an expression is used as an address. Errors will occur when the memory space attribute of the expression result does not match the explicit or implicit memory space specified in the source code. Memory spaces are explicit when the address has any of the following forms:

Attribute Explicit Address
X X:address_expression
Y Y:address_expression
L L:address_expression
P P:address_expression
E E:address_expression

Table 5-5: Memory space attributes

The memory space is implicitly P when an address is used as the operand of a DO, branch, or jump-type instruction.

Expressions used for immediate addressing can have any memory space attribute.

5.2.6 Example

/usr/src/dsp56/op_types.asm
M:LOC  CODE      CYCLES LINE SOURCELINE
P:0200                     1        org     p:$200
                           2 plab:
X:0100                     3        org     x:$100
                           4 xlab:
                           5 xlab2:
X:0100 000100              6        dc      plab-xlab
as56 W123: /usr/src/dsp56/op_types.asm line 6 :
 expression: illegal combination of memory spaces
X:0101 000200              7        dc      xlab+xlab2
as56 W123: /usr/src/dsp56/op_types.asm line 7 :
 expression: arithmetic on an address with an address
                           8
X:0102 000200              9        dc      xlab*2
as56 W123: /usr/src/dsp56/op_types.asm line 9 :
 expression: undefined arithmetic on an address
X:0103 000200             10        dc      @cvs(n,xlab)*2  
                                    ; use @CVS() so we can multiply
                          11        end

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

Table 5-6: 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:

$a342+$23       ; addition of absolute numbers
$ff1a-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
$ff3c/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<$0A      ; 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:

$B&3  ; result is 3
          %1011
          %0011  &
          %0011
~$A   ; result is $fffff5
          ~ %000000000000000000001010
          = %111111111111111111110101

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 or floating point.

Examples:

$B&&3     ; result is 1 (true)

!$A       ; 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 five types:

1. Mathematical functions

2. Conversion functions

3. String functions

4. Macro functions

5. Assembler mode functions

5.4.1 Mathematical Functions

The mathematical functions comprise transcendental, random value, and min/max functions, among others:

ABS - Absolute value

ACS - Arc cosine

ASN - Arc sine

AT2 - Arc tangent

ATN - Arc tangent

CEL - Ceiling function

COH - Hyperbolic cosine

COS - Cosine

FLR - Floor function

L10 - Log base 10

LOG - Natural logarithm

MAX - Maximum value

MIN - Minimum value

POW - Raise to a power

RND - Random value

SGN - Return sign

SIN - Sine

SNH - Hyperbolic sine

SQT - Square root

TAN - Tangent

TNH - Hyperbolic tangent

XPN - Exponential function

5.4.2 Conversion Functions

The conversion functions provide conversion between integer, floating point, and fixed point fractional values:

CVF - Convert integer to floating point

CVI - Convert floating point to integer

CVS - Convert memory space

FLD - Shift and mask operation

FRC - Convert floating point to fractional

LFR - Convert floating point to long fractional

LNG - Concatenate to double word

LUN - Convert long fractional to floating point

RVB - Reverse bits in field

UNF - Convert fractional to floating point

5.4.3 String Functions

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

LEN - Length of string

POS - Position of substring in string

SCP - Compare strings

5.4.4 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.5 Assembler Mode Functions

Miscellaneous functions having to do with assembler operation:

AS56 - Assembler executable name

DEF - Symbol definition function

DEFMEM - Default memory function

DSP - DSP processor type number

LST - LIST directive flag value

MODEL - Returns memory model

MSP - Memory space

STKMEM - Stack memory function

5.4.6 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 a floating point value. The memory space attribute of the result will be None.

Example:

@ACS(expression)

Returns the arc cosine of expression as a floating point value in the range zero to pi. The result of expression must be between -1 and 1. The memory space attribute of the result will be None.

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. The memory space attribute of the result will be None.

Example:

@AS56()

Returns the name of the assembler executable. This is as56 for the DSP5600x or as563 for the DSP563xx family.

Example:

@ASN(expression)

Returns the arc sine of expression as a floating point value in the range -pi/2 to pi/2. The result of expression must be between -1 and 1. The memory space attribute of the result will be None.

Example:

@AT2(expr1,expr2)

Returns the arc tangent of expr1/expr2 as a floating point value in the range -pi to pi. Expr1 and expr2 must be separated by a comma. The memory space attribute of the result will be None.

Example:

@ATN(expression)

Returns the arc tangent of expression as a floating point value in the range -pi/2 to pi/2. The memory space attribute of the result will be None.

Example:

@CEL(expression)

Returns a floating point value which represents the smallest integer greater than or equal to expression. The memory space attribute of the result will be None.

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. The memory space attribute of the result will be None.

Example:

@COH(expression)

Returns the hyperbolic cosine of expression as a floating point value. The memory space attribute of the result will be None.

Example:

@COS(expression)

Returns the cosine of expression as a floating point value. The memory space attribute of the result will be None.

Example:

@CVF(expression)

Converts the result of expression to a floating point value. The memory space attribute of the result will be None.

Example:

@CVI(expression)

Converts the result of expression to an integer value. This function should be used with caution since the conversions can be inexact (e.g., floating point values are truncated). The memory space attribute of the result will be None.

Example:

@CVS({X | Y | L | P | E | N },expression)

Converts the memory space attribute of expression to that specified by the first argument; returns expression. See section Memory Spaces for more information on memory space attributes. The expression may be relative or absolute.

Example:

@DEF(symbol)

Returns an integer 1 (memory space attribute N) if symbol has been defined, 0 otherwise. symbol may be any label not associated with a MACRO or SECTION 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:

@DEFMEM()

You can use the @DEFMEM() function just as the _DEFMEM function in the compiler to retrieve the selected default memory.

Example:

@DSP()

Returns an integer indicating the type of DSP56xxx processor family. This value is 0 for the DSP5600x, 3 for the DSP563xx family or 6 for the DSP566xx family.

Example:

@FLD(base,value,width[,start])

Shift and mask value into base for width bits beginning at bit start. If start is omitted, zero (least significant bit) is assumed. All arguments must be positive integers and none may be greater than the target word size. Returns the shifted and masked value with a memory space attribute of None.

Example:

@FLR(expression)

Returns a floating point value which represents the largest integer less than or equal to expression. The memory space attribute of the result will be None.

Example:

@FRC(expression)

This function performs scaling and convergent rounding to obtain the fractional representation of the floating point expression as an integer. The memory space attribute of the result will be None.

Example:

@L10(expression)

Returns the base 10 logarithm of expression as a floating point value. expression must be greater than zero. The memory space attribute of the result will be None.

Example:

@LEN(string)

Returns the length of string as an integer. The memory space attribute of the result will be None.

Example:

@LFR(expression)

This function performs scaling and convergent rounding to obtain the fractional representation of the floating point expression as a long integer. The memory space attribute of the result will be None.

Example:

@LNG(expr1,expr2)

Concatenates the single word expr1 and expr2 into a double word value such that expr1 is the high word and expr2 is the low word. The memory space attribute of the result will be None.

Example:

@LOG(expression)

Returns the natural logarithm of expression as a floating point value. expression must be greater than zero. The memory space attribute of the result will be None.

Example:

@LST()

Returns the value of the LIST directive flag as an integer, with a memory space attribute of None. Whenever a LIST directive is encountered in the assembler source, the flag is incremented; when a NOLIST directive is encountered, the flag is decremented.

Example:

@LUN(expression)

Converts the double-word expression to a floating point value. expression should represent a binary fraction. The memory space attribute of the result will be None.

Example:

@MAC(symbol)

Returns an integer 1 (memory space attribute N if symbol has been defined as a macro name, 0 otherwise.

Example:

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

Returns the greatest of expr1,...,exprN as a floating point value. The memory space attribute of the result will be None.

Example:

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

Returns the least of expr1,...,exprN as a floating point value. The memory space attribute of the result will be None.

Example:

@MODEL()

The @MODEL() function returns the memory model just as the_MODEL function in the compiler. The possible values are derived from the -M option.

Example:

@MSP(expression)

Returns the memory space attribute of expression as an integer value.

None = 0

X space = 1

Y space = 2

L space = 3

P space = 4

E space = 5

The expression may be relative or absolute.

Example:

@MXP()

Returns an integer 1 (memory space attribute N) 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. The memory space attribute of the result will be None.

Example:

@POW(expr1,expr2)

Returns expr1 raised to the power expr2 as a floating point value. expr1 and expr2 must be separated by a comma. The memory space attribute of the result will be None.

Example:

@RND()

Returns a random value in the range 0.0 to 1.0. The memory space attribute of the result will be None.

Example:

@RVB(expr1,expr2)

Reverse the bits in expr1 delimited by the number of bits in expr2. If expr2 is omitted the field is bounded by the target word size. Both expressions must be single word integer values.

Example:

@SCP(str1,str2)

Returns an integer 1 (memory space attribute N) if the two strings compare, 0 otherwise. The two strings must be separated by a comma.

Example:

@SGN(expression)

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

Example:

@SIN(expression)

Returns the sine of expression as a floating point value. The memory space attribute of the result will be None.

Example:

@SNH(expression)

Returns the hyperbolic sine of expression as a floating point value. The memory space attribute of the result will be None.

Example:

@SQT(expression)

Returns the square root of expression as a floating point value. expression must be positive. The memory space attribute of the result will be None.

Example:

@STKMEM()

You can use the @STKMEM() function just as the _STKMEM function in the compiler to retrieve the selected stack memory. @STKMEM only differs from @DEFMEM if the stack is placed in L memory for X or Y default memory.

Example:

@TAN(expression)

Returns the tangent of expression as a floating point value. The memory space attribute of the result will be None.

Example:

@TNH(expression)

Returns the hyperbolic tangent of expression as a floating point value. The memory space attribute of the result will be None.

Example:

@UNF(expression)

Converts expression to a floating point value. expression should represent a binary fraction. The memory space attribute of the result will be None.

Example:

@XPN(expression)

Returns the exponential function (base e raised to the power of expression) as a floating point value. The memory space attribute of the result will be None.

Example:


Copyright © 2002 Altium BV