If cc true: (SP-1) <- PCh, (SP-2) <- PCl, PC <- nn
CALL
cc,nn
b7 | b6 | b5 | b4 | b3 | b2 | b1 | b0 |
---|---|---|---|---|---|---|---|
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.
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.
cc | Hex | Condition | Relevant Flag |
---|---|---|---|
000 | $C4 | Non-Zero (NZ) | Z |
001 | $CC | Zero (Z) | Z |
010 | $D4 | No Carry (NC) | C |
011 | $DC | Carry (C) | C |
100 | $E4 | Parity Odd (PO) | P/V |
101 | $EC | Parity Even (PE) | P/V |
110 | $F4 | Sign Positive (P) | S |
111 | $FC | Sign Negative (M) | S |
None
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.
Location | Contents |
---|---|
$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.