miSim DE Back Index Next

Chapter 4 - Assembler Continued

Numeric Literals

The assembler recognises numbers (numeric literals) in the following formats:

TypeSyntaxExample
Default<hex_digits>1F3A
Decimal D'<digits>'
.<digits>
D'12'
.34
Hexadecimal     0x<hex_digits>     
H'<hex_digits>'
<hex_digits>h
0x1F
H'9c'
0Fh
Octal O'<octal_digits>'O'777'
Binary B'<binary_digits>'    B'111010'    
ASCII '<character>'
A'<character>'
'C'
A't'

Note that a number that is not prefixed with a specific radix indicator, it must start with a digit (0-9). As an example, the number 0xEF must be written 0EFh, rather than EFh, as the latter will not be recognised as a number.

So 0x30E is equivalent to B'1100001110' or D'782'. The default base (radix) for numbers is base 16 (hexadecimal), so a number 1234 in the listing is hex 1234, or 4660 decimal. However, the LIST and RADIX commands (explained later) allow the default base to be changed to decimal or octal.

In addition, some commands take string parameters - effectively sequences of character values. These are represented by text enclosed in quotes. An example might be:

Comments

Comments in the listing start with the semi-colon ';' character and continue to the end of the line. Comments may contain any combination of characters and are ignored by the assembler.

For example:

Labels

A Label is a text string that has an associated numeric value. A label is any sequence of characters, starting with a letter (A..Z,a..z) and including letters, numbers and underscore characters. Valid labels are 'myLabel', 'an_address', 'label234'. Invalid labels are '3again' (starts with a number) or 'as-were' (minus symbol is not valid in a label). Labels are not case-sensitive, so 'Hello','hello' and 'hELLO' are treated as the same. Instructions, special instructions and assembler commands are reserved and cannot be used as labels.

Numeric labels are created with either the SET, EQU or '=' commands. For example

Labels created with the EQU command are constants, and cannot be altered. Labels created with SET or '=' are variables, and can be assigned new values at any point after they have been initialised.

Address labels must start at the beginning of a new line. An address label may optionally be followed by a colon ':' character, which is ignored. The value of the address label will be the address immediately following the last assembled instruction.

Constant and address labels may be forward referenced - that is, they may be used in an instruction before they are given a value. However variable labels may not be used in this way, and forward references cannot be used in conditional assembly or macro commands.

Expressions

Numeric expressions consist of numeric literals and labels, and the following operators. The operators listed are grouped by precedence, with the highest precedence at the top:

OperatorExample
  *  Multiplylabel = 2*4
  / Dividelabel = 8/2
  % Moduluslabel = 8%3
  + Addlabel = 1+5
  - Subtractlabel = 2-2
  << Left shiftlabel = bits << 4
  >> Right shiftlabel = bits >> 1
  >= Greater or equalIF label >= 0
  > GreaterIF label > 1
  != Not equal toIF label != 4
  < LessIF label < 6
  <= Less or equalIF label <= 3
  == Equal toIF label==2
  & Bitwise ANDlabel = flags & 7
  | Bitwise ORlabel = flags | 8
  ^ Bitwise exclusive ORlabel = flags ^ 5
  && Logical ANDIF (label == 1) && (flags != 0)
  || Logical ORIF (label > 8) || (label < 2)
  = Set equal tolabel = 0
  += Add to, set equallabel += 2
  *= Multiply, set equallabel *= 3
  /= Divide, set equallabel /= 2
  -= Subtract, set equallabel -= 1
  %= Modulus, set equallabel %= 8
  <<=Left shift, set equallabel <<= 2
  >>=Right shift, set equallabel >>= 1
  &= AND, set equalflags &= 0x7
  |= OR, set equalflags |= 8
  ^= Exclusive OR, set equalflags ^= 1
  ++ Incrementlabel++
  -- Decrementlabel--

Normal operator precedence is observed and shown in the table above. Brackets ('(' and ')') can be used to control evaluation. The Increment (++) and decrement (--) operators must be used on a line of their own.

In addition the following unary operators are supported:

OperatorExample
  !  Logical NotIF !(label=3)
  ~  Complementlabel = ~label
  -  Negationlabel = -label

Finally the symbol '$' represents the current value of the program counter.

Index Next