CALL Control Flow

Call a subroutine, saving the return address on the hardware stack.

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

How it works

CALL pushes the address of the next instruction onto the 8-level hardware stack and jumps to k. The subroutine ends with RETURN or RETLW, which pops that address and continues after the CALL.

The stack is only 8 levels deep and holds return addresses only; there are no push or pop instructions for data.

Example

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

    org 0
    call double       ; W = 0x14 when it returns
    movwf 0x20        ; 0x20 = 0x14
done:
    goto done
double:
    movlw 0x0A
    addlw 0x0A
    return

Step into the CALL and watch the Stack widget: the return address is pushed, then popped by RETURN.

Open this example in the simulator

Watch out for

  • A ninth nested CALL (counting interrupts) overwrites the oldest return address on a real PIC. The simulator stops with a stack-overflow error instead so you can find it.

Related instructions