R.O.M.E.68000 Home
Prev. Table of Cont. Help Cont. of This Ch.

This is the R.O.M.E.68000 Manual version 0.51.
This is an experimental version.
Copyright © 1997 by G. Mezzetti; last update: January 1, 1999.

7. The Instruction Pointer

CW programs cannot make use of registers contained internally in the virtual processor: all data must be kept in the memory array and manipulated there. The only exception to this rule is the instruction pointer (abbreviated as IP), which is the register that points to the next instruction to execute; it is an actual register, held internally in the CPU: don't confuse it with registers understood as special locations of the core! The instruction pointer appears as an implicit operand in many instructions: first of all, it is used implicitly in all jump instructions, both conditional and unconditional, but besides these it is also involved in all those instructions that can perform a conditional (or even unconditional) skip. The latter include the SKcc family as well as the SKIP instruction (see Section 4 and Section 5 of Chapter IV), the CMPRBW, CHKDBW, CHKBBW, and FNDUBW instructions (described in Section 6 and Section 7 of Chapter IV), but also other instructions that can signal an error condition by skipping or not one or more locations (for instance, the SPL instruction, described in Chapter VII). Finally, the instruction pointer can even be written to the core by the JSBR instruction, which jumps to a subroutine, and be read back by the RTN instruction, which returns from it.

Since it is contained within the virtual processor, and not lodged in the memory array, the instruction pointer is an absolute pointer, not a relative one [1]: as mentioned before, it contains always an absolute pointer to the next instruction to execute. Under normal circumstances, this is the instruction that comes next to the one currently being executed, as shown in fig. 20:

Figure 20: Position of the instruction pointer with respect to the current instruction

Of course, the position of the instruction pointer can change because of a jump or skip instruction, in such a way to point always to the location which, at any given moment. is presumed to be the one that contains the next instruction to execute. It is important to be familiar with this convention, in order to fully understand the behaviour of the instructions that manipulate the instruction pointer: let us review it in more detail.

At the beginning of each execution cycle, the contents of the location pointed at by the instruction pointer are copied in an internal register (the instruction register); immediately after this, and before any other action is undertaken, the instruction pointer is incremented; in particular, this is done before the beginning of the actual execution of the instruction. When the instruction is being executed, hence, the IP is already pointing to the next instruction to execute, as said; if the current instruction does not alter it, this will be the instruction that will be fetched on the next cycle. On the other hand, if the current instruction must alter the normal flow of the program, it does so by loading a new value into the IP, which will be again the address (the absolute address!) of the next instruction to execute (e.g., of the target of the jump). The different situations that can occur are illustrated in fig. 21, 22 and 23.

Figure 21: Movement of IP during sequential execution

Figure 22: Movement of IP during a jump

Figure 23: Movement of IP during a skip

These figures are all but self-explanatory. On the left-hand side of fig. 21, which shows the case of sequential execution, you can see the position of IP while the instruction word is being read, and on the right-hand side you see that the instruction pointer is incremented to point to the next instruction to execute. In fig. 22, in which the case of a jump instruction is depicted, the first two stages are the same as in the previous case, but before the instruction is completed a new value is loaded into the instruction pointer, to make it point to the target of the jump. Finally, fig. 23 illustrates the case of a skip instruction: after reading the instruction word, the instruction pointer is incremented as usual, but then it is incremented again during the execution of the instruction to make the skip take place; in this example, the next instruction to execute is the one sitting two location beyond the current one, but there are also instructions that can skip more than one location.

Prev. Table of Cont. Help Cont. of This Ch.


[1] When saved to the memory array, the instruction pointer is always written as a relative pointer.

Gustavo MEZZETTI  /  mezzetti@math.unipd.it