GOTO Control Flow

Jump unconditionally to an address or label.

SyntaxGOTO k
Operandsk: 11-bit program address 0-2047 (PCLATH<4:3> supplies the page on larger devices)
Operationk → PC<10:0>, PCLATH<4:3> → PC<12:11>
Status bitsNone
Words / cycles1 word, 2 cycles
Encoding10 1kkk kkkk kkkk

How it works

GOTO loads the program counter with the 11-bit address k, so execution continues there. It takes 2 cycles because the instruction already fetched is thrown away.

The upper bits of the address come from PCLATH<4:3>. On the PIC16F84A and PIC16F628A all program memory fits in the first 2K page, so PCLATH can stay 0; on the 4K PIC16F648A, jumping to page 1 needs PAGESEL first.

Example

; GOTO example from picsimulator.com/instructions/goto.html
    list p=16f84a
    include <p16f84a.inc>

    org 0
    goto start
    movlw 0xFF        ; never runs
start:
    movlw 0x01        ; W = 0x01

The MOVLW 0xFF after the GOTO is never executed, so W ends at 0x01.

Open this example in the simulator

Watch out for

  • GOTO $ (jump to itself) is the usual way to stop a program: the PIC never halts on its own.

Related instructions