[NEXT] [PREV]    HANDBOOK / CASE STUDY / The Target Machine /

The ICode Machine

Gentle
Applications
Concepts
Examples
Handbook
Support
Download

The ICode Machine consists of three registers and memory. The registers are

  • PC the program counter
  • SP the stack pointer
  • AP the activation record pointer

The program counter points to the current instruction in the memory. The stack pointer points to the highest occupied stack cell. The activation record pointer points to the `static link' field of the current activation record.

The memory is divided in two parts, one containing the program (Code) and the other containing data (Store). Code is an array of ICode instructions. Store is organized as stack (growing upwards) which contains the data of the program executed. Each activation of a procedure results in pushing an activation record on the stack, which contains storage for parameters and local data.

An activation record has the following layout:


          |------------------------|
          |                        | store for
          |                        | local data
          |------------------------|
          | - values of            |
          |   value parameters     | store for
          | - addresses of         | parameters
          |   reference parameters |
          |------------------------|
          | return address         |
          |------------------------| procedure call
          | dynamic link           |
          |------------------------| information
   AP --> | static link            |
          |------------------------|
At initialization time, the static and dynamic links and the return address of the main program are all set to 0. The registers are initialized as follows: PC := 0, SP := 3, and AP := 1. The start address is 0, i.e. Code [0] contains the first ICode instruction to be executed. PC is incremented before the according instruction is executed. The interpreter stops at return from the main program. The stop condition is: (PC = 0).

A procedure call enforces

  • the creation of static and dynamic links of the new activation record ( ICode instruction: MST)
  • parameter passing: The values of value parameters and the addresses of reference parameters are evaluated and pushed on the stack.

  • storing the return address and a jump to the procedure ( ICode instruction: JSR)
  • reservation of store for local data of the new activation record ( ICode instruction: ENT)

A return from a procedure enforces

  • discarding the current activation record by updating the registers





[NEXT] [PREV]