Next Previous Contents

4. Expressions

4.1 Expression evaluation

All expressions are evaluated with (at least) 32 bit precision. An expression may contain constant values and any combination of internal and external symbols. Expressions that cannot be evaluated at assembly time are stored inside the object file for evaluation by the linker. Expressions referencing imported symbols must always be evaluated by the linker.

4.2 Size of an expressions result

Sometimes, the assembler must know about the size of the value that is the result of an expression. This is usually the case, if a decision has to be made, to generate a zero page or an absolute memory references. In this case, the assembler has to make some assumptions about the result of an expression:

Note: If the assembler is not able to evaluate the expression at assembly time, the linker will evaluate it and check for range errors as soon as the result is known.

4.3 Boolean expressions

In the context of a boolean expression, any non zero value is evaluated as true, any other value to false. The result of a boolean expression is 1 if it's true, and zero if it's false. There are boolean operators with extrem low precedence with version 2.x (where x > 0). The .AND and .OR operators are shortcut operators. That is, if the result of the expression is already known, after evaluating the left hand side, the right hand side is not evaluated.

4.4 Available operators

Available operators sorted by precedence:

    Op          Description                             Precedence
  -------------------------------------------------------------------
    .CONCAT     Builtin function                        0
    .LEFT       Builtin function                        0
    .MID        Builtin function                        0
    .RIGHT      Builtin function                        0
    .STRING     Builtin function                        0

    *           Builtin pseudo variable (r/o)           1
    .BLANK      Builtin function                        1
    .CONST      Builtin function                        1
    .CPU        Builtin pseudo variable (r/o)           1
    .DEFINED    Builtin function                        1
    .MATCH      Builtin function                        1
    .TCOUNT     Builtin function                        1
    .XMATCH     Builtin function                        1
    .PARAMCOUNT Builtin pseudo variable (r/o)           1
    .REFERENCED Builtin function                        1
    ::          Global namespace override               1
    +           Unary plus                              1
    -           Unary minus                             1
    ~           Unary bitwise not                       1
    .BITNOT     Unary bitwise not                       1
    <           Low byte operator                       1
    >           High byte operator                      1

    *           Multiplication                          2
    /           Division                                2
    .MOD        Modulo operation                        2
    &           Bitwise and                             2
    .BITAND     Bitwise and                             2
    ^           Bitwise xor                             2
    .BITXOR     Bitwise xor                             2
    <<          Shift left operator                     2
    .SHL        Shift left operator                     2
    >>          Shift right operator
    .SHR        Shift right operator                    2

    +           Binary plus                             3
    -           Binary minus                            3
    |           Binary or                               3
    .BITOR      Binary or                               3

    =           Compare operation (equal)               4
    <>          Compare operation (not equal)           4
    <           Compare operation (less)                4
    >           Compare operation (greater)             4
    <=          Compare operation (less or equal)       4
    >=          Compare operation (greater or equal)    4

    &&          Boolean and                             5
    .AND        Boolean and                             5
    .XOR        Boolean xor                             5

    ||          Boolean or                              6
    .OR         Boolean or                              6

    !           Boolean not                             7
    .NOT        Boolean not                             7

To force a specific order of evaluation, braces may be used as usual.

Some of the pseudo variables mentioned above need some more explanation:

  *             This symbol is replaced by the value of the program
                counter at start of the current instruction. Note, that
                '*' yields a rvalue, that means, you cannot assign to it.
                Use <tt/.ORG/ to set the program counter in sections with
                absolute code.


Next Previous Contents