CALL cc,nn

Operation

If cc true: (SP-1) <- PCh, (SP-2) <- PCl, PC <- nn

Mnemonic

CALL

Operands

cc,nn

b7b6b5b4b3b2b1b0
1 1 cc 1 0 0
n
n

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

Description

If condition cc is true, this instruction pushes the current contents of the Program Counter (PC) onto the top of the external memory stack, then loads the operands nn to 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 PC. If condition cc is false, the Program Counter is incremented as usual, and the program continues with the next sequential instruction. The stack push is accomplished by first decrementing the current contents of the Stack Pointer (SP), loading the high-order byte of the PC contents to the memory address now pointed to by SP; then decrementing SP again, and loading the low-order byte of the PC contents to the top of the stack.

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

Condition cc is programmed as one of eight statuses that corresponds to condition bits in the Flag Register (Register F). These eight statuses are defined in the following table, which also specifies the corresponding cc bit fields in the assembled object code.

ccHexConditionRelevant
Flag
000$C4Non-Zero (NZ)Z
001$CCZero (Z)Z
010$D4No Carry (NC)C
011$DCCarry (C)C
100$E4Parity Odd (PO)P/V
101$ECParity Even (PE)P/V
110$F4Sign Positive (P)S
111$FCSign Negative (M)S

Condition Bits Affected

None

Example

The C Flag in the F Register is reset, the Program Counter contains $1A47, the Stack Pointer contains $3002, and memory locations contain the following data.

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

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

	CALL	NC,$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.