GOTO (0xA7)


The GOTO is an unconditional branch. Its operand is a two-byte signed integer offset. This offset is added to the address from which the GOTO opcode was read to yield the address of the next opcode.

In assembly code, the operand is a program label within the same method as the GOTO statement. The assembler uses the label address to calculate the correct offset.

Interpreter Microcode

The microinstructions are listed in the order in which they are executed; not the order in which they are stored in the control store.

0x0a7  OPC=PC-1; goto 0x2f
...
0x02f  PC=PC+1; fetch; goto 0x30
0x030  H=MBR<<8; goto 0x31
0x031  H=H OR MBRU; goto 0x32
0x032  PC=H+OPC; fetch; goto 0x33
0x033  ALU=0; goto 0x2

Example Program

//---------------------------------------------
// Demonstrate the GOTO instruction.
//
// 1. Clear Memory
// 2. Assemble this program.
// 3. Reset the computer.
// 4. Click the "Display Words" radio button
//    below the memory display.
// 5. Click the "Run" button.
//
// After running this program
//     10 is stored at address 4097
//     30 is stored at address 4098
//     20 is stored at address 4099
// and the top of the stack is at 4099.
//
// We used to call this spaghetti code.
//---------------------------------------------
.main
    bipush 10
    goto b
a:  bipush 20
    goto c
b:  bipush 30
    goto a
c:  halt
.end-main