University of Toronto
CSC467F Compilers and Interpreters Fall 2005

Target Machine Description

The machine has the following components.
  1. A main memory, consisting of memorySize words, numbered 0 to memorySize - 1. A number specifying a word in memory is called an address. Each word is 16 bits. The bit-pattern in a word may be interpreted in any of the following ways:
    1. An integer value in the range -32767 to +32767. The representation is two's complement.
    2. A boolean value. false is represented the same as integer 0; true is represented the same as integer 1.
    3. A character value (one character per word). The representation is ASCII, extended to 16 bits by prefixing 8 zeros.
    4. The undefined data value represented by -32768.
    5. An operation code. The operations and codes are listed below.
    6. A memory address.
  2. A 16-bit register pc (program counter), which contains the address of the next instruction to be executed.
  3. A 16-bit register mt (memory top), which contains the address of the next free word of memory.
  4. Some 16-bit registers display, numbered 0 to TT>displaySize - 1. These are used to make the variables of visible lexical levels addressable.

At the start of execution, the following may be presumed.

  1. The instructions of a program occupy contiguous memory locations starting at word 0.
  2. Register mt contains the address of the first word after the instructions.
  3. The rest of memory contains garbage.
  4. The display contains garbage.
  5. pc contains the address of the first instruction to be executed.

Beginning after the instructions, space is allocated for variables, and made addressable via the display, as required. Space required for intermediate results in the evaluation of expressions is at the top of the used portion of memory (the Evaluation Stack).

An instruction may occupy one, two, or three words of memory. The first word contains an op-code, specifying which machine operation to perform. The second and third words, if present, contain operands. In the following description, push, pop, and top refer to the memory considered as a stack whose top pointer is mt. Variables a, v, n, x and y are local to the description.

Machine Instructions

 0    ADDR LL ON  push (display [LL] + ON)
 1    LOAD        a := top; pop;
                  if memory [a] = undefined then error;
                  push (memory [a])
 2    STORE       v := top; pop;
                  a := top; pop;
                  memory [a] := v
 3    PUSH V      push (V)
 4    PUSHMT      push (mt)
 5    SETD LL     display [LL] := top; pop
 6    POPN        n := top; pop; pop n times
 7    POP         pop
 8    DUPN        n:= top; pop; v:= top; pop; push (v) n times
 9    DUP         push (top)
10    BR          a := top; pop; go to a
11    BF          a:= top; pop; v:= top; pop; if v = false then go to a
12    NEG         top := - top 
13    ADD         For operations 13-19:
14    SUB             y := top; pop;
15    MUL             x := top; pop;
16    DIV             n := x op y ;
17    EQ              if overflow or zerodivide then error else push (n);
18    LT
19    OR
20    SWAP        x:= top; pop; y:= top; pop; push(x); push(y)
21    READC       One character of input is read and pushed.
22    PRINTC      Print top as character; pop
23    READI       Starting at the current character of input, blanks and
                  line boundaries are read and ignored up to the next
                  digit or sign (if first non-blank is something else
                  then error). Then consecutive digits are read up to
                  the first non-digit; They are converted to an integer
                  n; push( n ).
24 PRINTI         Print top as integer; pop
25 HALT           Halt

Note: The following two pseudo instructions, TRON and TROFF, are provided as aids to assist in the debugging of the code generator.

26    TRON        Start tracing the execution of machine instructions
                  if tracing has been enabled.
27    TROFF       Stop tracing the execution of machine instructions.
                  Non-op if tracing not enabled.

Frank Van Bussel
Last modified October, 2005