Whereas the PC contains a pointer to external memory that speci-
fies the address of the next instruction to be executed, the SP contains
a pointer to an external memory stack. The concept of a memory
stack is not unique to microprocessors, but virtually every micro-
processor does have stack capability. The external memory stack is
simply an area of memory set aside for temporary storage of CPU
registers, the flag register, and the program counter. Certain instruc-
tions cause transfer of control from the current
jump
or
branch
in-
EXTERNAL
MEMORY
LOCATION
0100
0101
0103
0106
0107
0108
0109
O10B
O10D
INSTRUCTION 1 (1 BYTE)
INSTRUCTION 2 (2 BYTES)
INSTRUCTION 3(3 BYTES)
INSTRUCTION 4 (1 BYTE)
INSTRUCTION 5(1 BYTE)
INSTRUCTION 6 (1 BYTE)
INSTRUCTION 7 (2 BYTES)
INSTRUCTION 8 (2 BYTES)
* ALL VALUES HEXADECIMAL
CONTENTS OF
PC AT END OF
INSTRUCTION
0101
0103
0106
0107
0108
0109
0108
01OD
Fig. 2
-
7. Program counter operation.
struction to another instruction and cause the current contents of the
program counter (pointing to the instruction after the jump or
branch) to be automatically saved in the stack area. This saves the
location so that at some later time a return may be made back to the
next instruction in sequence after the jump or branch.
Not only is the PC saved for certain types of jumps or branches,
but it is automatically saved for
interrupts.
Here, the address of the
current instruction being executed is saved in the stack as the inter-
rupt occurs and a special interrupt processing routine is entered.
This action will be discussed in detail in a later chapter in this sec-
tion. Lastly, CPU registers and the flag register may be saved and
retrieved from the stack under program control using special stack
instructions.
As data is entered or
pushed
into the stack area, the stack pointer
is decremented by one count. As data is retrieved from the stack or
pulled,
the stack pointer is incremented by one count. A good anal-
ogy to stack operation is a poker hand that is laid down on the table
in a pile consisting of King of Hearts, Jack of Spades, and Ace of
Diamonds with the King at the bottom. When the cards are re-
trieved, the first card picked up is the last laid down, the Ace of
Diamonds, followed by Jack of Spades and King of Hearts. This type
20