Previous [TOC] Next

| 6 Jump Instructions

The jump instructions are of four types: unconditional, conditional, indexed, or absolute. The conditional jumps test against zero or compare two signed or unsigned operands. The indexed jumps index tables of displacements found in the current code segment. They are used to implement case statements. All jumps are program-counter-relative, and all displacements are measured in bytes, relative to the first byte of the instruction (recorded in savedPC). The following example shows the two possible successors of a Jump Less Byte instruction (defined in §6.3):

Figure 6.1 Jump Addressing

Note: Most of the jump opcodes add signed displacements, obtained by sign-extending alpha, to the unsigned `PC`. The only unsigned jump displacements are in the Jump Indexed instructions. All but JIW have their displacement in [-32768..32767]. Arithmetic on the `PC` is always performed modulo 216, and overflow is ignored.

### 6.1 Unconditional Jumps

These instructions add a small constant, a sign-extended byte, or an `INTEGER` to the `PC`.

#### Jn Jump n

    Jn: PROCEDURE [n: [2..8]] =
        BEGIN
        PC  savedPC + n;
        END;

#### JB Jump Byte

    JB: PROCEDURE =
        BEGIN
        disp: BYTE = GetCodeByte[];
        PC  savedPC + SignExtend[disp];
        END;

#### JW Jump Word

    JW: PROCEDURE =
        BEGlN
        disp: INTEGER = GetCodeWord[];
        PC  savedPC + disp;
        END;

The Jump Stack instruction sets the `PC` to the value popped from the stack:

#### JS Jump Stack

    JS: PROCEDURE =
        BEGIN
        PC  Pop[];
        END;

The Catch instruction is used by the software to mark the code and indicate (in alpha) the catch phrase index. Except for its effects on the `PC`, Catch is a no-op.

#### CATCH Catch

    CATCH: PROCEDURE =
        BEGIN
        alpha: BYTE = GetCodeByte[];
        END;

### 6.2 Equality Jumps

The equality jumps compare the top two elements of the stack or the top element and a constant (alpha or zero) for equality and jump accordingly. The jump pair opcodes compare the top of the stack with a four-bit field of alpha, and add a second four-bit field of alpha to the `PC` if the comparison succeeds.

#### JZn Jump Zero n

    JZn: PROCEDURE [n: [3 4]] =
        BEGIN
        u: UNSPECIFIED = Pop[];
        IF u = 0 THEN PC  savedPC + n;
        END;

#### JNZn Jump Not Zero n

    JNZn: PROCEDURE [n:  [3..4]] =
        BEGIN
        u: UNSPECIFIED = Pop[];
        IF u # 0 THEN PC  savedPC + n;
        END;

#### JZB Jump Zero Byte

    JZB: PROCEDURE =
        BEGIN
        disp: BYTE = GetCodeByte[];
        data: UNSPECIFIED = Pop[];
        IF data = 0 THEN PC  savedPC + SignExtend[disp];
        END;

#### JNZB Jump Not Zero Byte

    JNZB: PROCEDURE =
        BEGIN
        disp: BYTE = GetCodeByte[];
        data: UNSPECIFIED = Pop[];
        IF data # 0 THEN PC  savedPC + SignExtend[disp];
        END;

#### JEB Jump Equal Byte

    JEB: PROCEDURE =
        BEGIN
        disp: BYTE = GetCodeByte[];
        v: UNSPECIFIED = Pop[];
        u: UNSPECIFIED = Pop[];
        IF u = v THEN PC  savedPC + SignExtend[disp];
        END;

#### JNEB Jump Not Equal Byte

    JNEB: PROCEDURE =
        BEGIN
        disp: BYTE = GetCodeByte[];
        v: UNSPECIFIED = Pop[];
        u: UNSPECIFIED = Pop[];
        IF u # v THEN PC  savedPC + SignExtend[disp];
        END;

#### JDEB Jump Double Equal Byte

    JDEB: PROCEDURE =
        BEGIN
        disp: BYTE = GetCodeByte[];
        v: LONG UNSPECIFIED = PopLong[];
        u: LONG UNSPECIFIED = PopLong[];
        IF u = v THEN PC  savedPC + SignExtend[disp];
        END;

#### JDNEB Jump Double Not Equal Byte

    JDNEB: PROCEDURE =
        BEGIN
        disp: BYTE = GetCodeByte[];
        v: LONG UNSPECIFIED = PopLong[];
        u: LONG UNSPECIFIED = PopLong[];
        IF u # v THEN PC  savedPC + SignExtend[disp];
        END;

#### JEP Jump Equal Pair

    JEP: PROCEDURE =
        BEGIN
        pair: NibblePair = GetCodeByte[];
        data: UNSPECIFIED = Pop[];
        IF data = pair.left THEN PC  savedPC + pair.right + 4;
        END;

#### JNEP Jump Not Equal Pair

    JNEP: PROCEDURE =
        BEGIN
        pair: NibblePair = GetCodeByte[];
        data: UNSPECIFIED = Pop[];
        IF data # pair.left THEN PC  savedPC + pair.right + 4;
        END;

#### JEBB Jump Equal Byte Byte

    JEBB: PROCEDURE =
        BEGIN
        byte: UNSPECIFIED = GetCodeByte[];
        disp: BYTE = GetCodeByte[];
        data: UNSPECIFIED = Pop[];
        IF data = byte THEN PC  savedPC + SignExtend[disp];
        END;

#### JNEBB Jump Not Equal Byte Byte

    JNEBB: PROCEDURE =
        BEGIN
        byte: UNSPECIFIED = GetCodeByte[];
        disp: BYTE = GetCodeByte[];
        data: UNSPECIFIED = Pop[];
        IF data # byte THEN PC  savedPC + SignExtend[disp];
        END;

### 6.3 Signed Jumps

The signed jump instructions compare the top two elements of the stack as two's complement signed operands and add a sign-extended alpha to the `PC` if the comparison succeeds.

#### JLB Jump Less Byte

    JLB: PROCEDURE =
        BEGIN
        disp: BYTE = GetCodeByte[];
        k: INTEGER = Pop[];
        j: INTEGER = Pop[];
        IF j < k THEN PC  savedPC + SignExtend[disp];
        END;

#### JLEB Jump Less Equal Byte

    JLEB: PROCEDURE =
        BEGIN
        disp: BYTE = GetCodeByte[];
        k: INTEGER = Pop[];
        j: INTEGER = Pop[];
        IF j <= k THEN PC  savedPC + SignExtend[disp];
        END;

#### JGB Jump Greater Byte

    JGB: PROCEDURE =
         BEGIN
         disp: BYTE = GetCodeByte[];
         k: INTEGER = Pop[];
         j: INTEGER = Pop[];
         IF j > k THEN PC  savedPC + SignExtend[disp];
         END;

#### JGEB Jump Greater Equal Byte

    JGEB: PROCEDURE =
        BEGIN
        disp: BYTE = GetCodeByte[];
        k: INTEGER = Pop[];
        j: INTEGER = Pop[];
        IF j >= k  THEN PC  savedPC + SignExtend[disp];
        END;

### 6.4 Unsigned Jumps

The unsigned jump instructions compare the top two elements of the stack as unsigned operands and add a sign-extended alpha to the `PC` if the comparison succeeds.

#### JULB Jump Unsigned Less Byte

    JULB: PROCEDURE =
        BEGIN
        disp: BYTE = GetCodeByte[];
        v: CARDINAL = Pop[];
        u: CARDINAL = Pop[];
        IF u < v THEN PC  savedPC + SignExtend[disp];
        END;

#### JULEB Jump Unsigned Less Equal Byte

    JULEB: PROCEDURE =
        BEGIN
        disp: BYTE = GetCodeByte[];
        v: CARDINAL = Pop[];
        u: CARDINAL = Pop[];
        IF u <= v THEN PC  savedPC + SignExtend[disp];
        END;

#### JUGB Jump Unsigned Greater Byte

    JUGB: PROCEDURE =
        BEGIN
        disp: BYTE = GetCodeByte[];
        v: CARDINAL = Pop[];
        u: CARDINAL = Pop[];
        IF u > v THEN PC  savedPC + SignExtend[disp];
        END;

#### JUGEB Jump Unsigned Greater Equal Byte

    JUGEB: PROCEDURE =
        BEGIN
        disp: BYTE = GetCodeByte[];
        v: CARDINAL = Pop[];
        u: CARDINAL = Pop[];
        IF u >= v THEN PC  savedPC + SignExtend[disp];
        END;

### 6.5 Indexed Jumps

The indexed jumps update the `PC` from a table of byte displacements located in the code segment at offset base from the code base `CB`. If index is less than limit, the index added to base is used to extract a displacement from a table located in the current code segment. This displacement is then added to the `PC`. If index is out of range, no jump occurs.

Jump Indexed Byte uses a table of eight-bit entries, Jump Indexed Word uses sixteen-bit entries. The entries in both tables contain displacements measured in bytes. Note that in `JIB`, the displacement is not sign-extended.

#### JIB Jump Indexed Byte

    JIB: PROCEDURE =
        BEGIN
        disp: BytePair;
        base: CARDINAL = GetCodeWord[];
        limit: CARDINAL = Pop[];
        index: CARDINAL = Pop[];
        IF index < limit THEN
            BEGIN
            disp  ReadCode[base + index/2];
            PC  savedPC + (IF (index MOD 2) = 0 THEN
                disp.left ELSE disp.right);
            END;
        END;

#### JIW Jump Indexed Word

    JIW: PROCEDURE =
        BEGIN
        disp: CARDINAL;
        base: CARDINAL = GetCodeWord[];
        limit: CARDINAL = Pop[];
        index: CARDINAL = Pop[];
        IF index < limit THEN
            BEGIN
            disp  ReadCode[base + index];
            PC  savedPC + disp;
            END;
        END;

The ReadCode routine is defined in §3.1.4.3.

Previous [TOC] Next

[last edited 5/4/99 9:32PM]