alien.png TASM Docs -- Expressions

[Previous] [Main] [Next]


Expressions are made up of various syntactic elements combined according to a set of syntactical rules. Expressions can be comprised of the following elements:
·Labels  
·Constants  
·Location Counter Symbol  
·Operators  
·Parenthesis  

Labels

Labels are strings of characters that have a numeric value associated with them, generally representing an address. Labels can contain upper and lower case letters, digits, underscores, and periods. The first character must be a letter or the local label prefix (default '_'). The value of a label is limited to 32 bit precision. Labels can contain up to 32 characters, all of which are significant (none are ignored when looking at a label's value, as in some assemblers). Case is significant unless the '-i' command line option is invoked.
Local labels must only be unique within the scope of the current module. Modules are defined with the MODULE directive. Here is an example:

          .MODULE xxx
          lda regx
          jne _skip
          dec
   _skip  rts

          .MODULE yyy
          lda regy
          jne _skip
          dec
   _skip  rts

In the above example, the _skip label is reused without harm. As a default, local labels are not shown in the label table listing (resulting from the '-l' command line option). See also sections on MODULE and LOCALLABELCHAR directives.

Numeric Constants

Numeric constants must always begin with a decimal digit (thus hexadecimal constants that start with a letter must be prefixed by a '0' unless the '$' prefix is used). The radix is determined by a letter immediately following the digit string according to the following table:

Radix      Suffix         Prefix
   
2         B or b         %    
8         O or o         @    
10         D or d (or nothing)       
16         H or h         $    

Decimal is the default radix, so decimal constants need no suffix or prefix.

The following representations are equivalent:

  1234H          or     $1234
  100d           or     100
  177400o        or     @177400
  01011000b      or     %01011000

The prefixes are provided for compatibility with some other source code formats but introduce a problem of ambiguity. Both '%' and '$' have alternate uses ('%' for modulo, '$' for location counter symbol). The ambiguity is resolved by examining the context. The '%' character is interpreted as the modulo operator only if it is in a position suitable for a binary operator. Similarly, if the first character following a '$' is a valid hexadecimal digit, it is assumed to be a radix specifier and not the location counter.

Character Constants

Character constants are single characters surrounded by single quotes. The ASCII value of the character in the quotes is returned. No escape provision exists to represent non-printable characters within the quotes, but this is not necessary since these can be just as easily represented as numeric constants (or using the TEXT directive which does allow escapes).

String Constants

String constants are one or more characters surrounded by double quotes. Note that string constants are not allowed in expressions. They are only allowable following the TITLE, BYTE, DB, and TEXT assembler directives. The quoted strings may also contain escape sequences to put in unprintable values. The following escape sequences are supported:

Escape   Sequence   Description    
\n            Line Feed
\r            Carriage return
\b            Backspace
\t            Tab
\f            Formfeed
\\            Backslash
\"            Quote
\000         Octal value of character

Location Counter Symbol

The current value of the location counter (PC) can be used in expressions by placing a '$' in the desired place. The Location Counter Symbol is allowable anywhere a numeric constant is. (Note that if the '$' is followed by a decimal digit then it is taken to be the hexadecimal radix indicator instead of the Location Counter symbol, as mentioned above). The '*' may also be used to represent the location counter, but is less preferred because of its ambiguity with the multiplicative operator.

Operators

Expressions can optionally contain operators to perform some alterations or calculations on particular values. The operators are summarized as follows:

Operator   Type         Description    
+         Additive      addition    
-                   subtraction    

*         Multiplicative      multiplication    
/                  division
%                  modulo
<<                  logical shift left
>>                  logical shift right

~         Unary         bit inversion (one's complement)
-                  unary negation

=         Relational      equal
==                  equal
!=                  not equal
<                  less than
>                  greater than
<=                  less than or equal
>=                  greater than or equal

&         Binary         binary 'and'
|                  binary 'or'
^                  binary 'exclusive or'

The syntax is much the same as in 'C' with the following notes.

·No operator precedence is in effect. Evaluation is from left to right unless grouped by parenthesis (see example below).  
·All evaluations are done with 32 bit signed precision.  
·Both '=' and '==' are allowable equality checkers. This is allowed since the syntax does not provide assignment capability (as '=' would normally imply).  

The relational operators return a value of 1 if the relation is true and 0 if it is false. Thirty-two bit signed arithmetic is used.
It is always a good idea to explicitly indicate the desired order of evaluation with parenthesis, especially to maintain portability since TASM does not evaluate expressions in the same manner as many other assemblers. To understand how it does arrive at the values for expressions, consider the following example:

  1 + 2*3 + 4

TASM would evaluate this as:
  (((1 + 2) * 3) + 4) = 13


Typical rules of precedence would cause the (2*3) to be evaluated first, such as:
  1 + (2*3) + 4      = 11

To make sure you get the desired order of evaluation, use parenthesis liberally. Here are some examples of valid expressions:
  (0f800H + tab)
  (label_2 >> 8)
  (label_3 << 8) & $f000
  $ + 4
  010010000100100b + 'a'
  (base + ((label_4 >> 5) & (mask << 2))




TASM. Copyright (C) 1998 by Squak Valley Software.
All rights reserved.