CALL nn

Operation

(SP-1) <- PCh, (SP-2) <- PCl, PC <- nn

Mnemonic

CALL

Operands

nn

b7b6b5b4b3b2b1b0
1 1 0 0 1 0 1 1$CD
n
n

Note: The first operand in this assembled object code is the low-order byte of a two-byte address.

Description

The current contents of the Program Counter (PC) are pushed onto the top of the external memory stack. The operands nn are then loaded to the PC to point to the address in memory at which the first op code of a subroutine is to be fetched. At the end of the subroutine, a RETurn instruction can be used to return to the original program flow by popping the top of the stack back to the PC. The push is accomplished by first decrementing the current contents of the Stack Pointer (register pair SP), loading the high-order byte of the PC contents to the memory address now pointed to by the SP; then decrementing SP again, and loading the low-order byte of the PC contents to the top of stack.

Because this process is a 3-byte instruction, the Program Counter was incremented by three before the push is executed.

Condition Bits Affected

None

Example

The Program Counter contains $1A47, the Stack Pointer contains $3002, and memory locations contain the following data.

LocationContents
$1A47$CD
$1A48$35
$1A49$21

If an instruction fetch sequence begins, the 3-byte instruction $CD $3521 is fetched to the CPU for execution. The mnemonic equivalent of this instruction is

	CALL	$2135

Upon the execution of this instruction, memory address $3001 contains $1A, address $3000 contains $4A, the Stack Pointer contains $3000, and the Program Counter contains $2135, thereby pointing to the address of the first op code of the next subroutine to be executed.