Download Print this page

RCA COSMAC User Manual page 52

Hide thumbs Also See for COSMAC:

Advertisement

COSMAC Microprocessor ______________________________ _
51
Detailed study of the sample program shown in Fig. 56 will provide a basic understanding of the use of
the individual instructions.
Useful I nstructions with X
=
P
There are three instructions which have particular usefulness when X is set equal to P: the OUTPUT
instructions (60-67), the RETURN instruction (70), and the DISABLE instruction (71)_ Since each of
these instructions increments the R (X) register, when X=P the R (P)/R (X) register will be incremented once
for the fetch cycle when it acts as program counter and once for the execute cycle. As a result, the byte
immediately following the instruction byte is the operand byte. For example, if P=3, the
sequenc~
v/ill
E3
60
AD
output the byte "AD" by means of the data bus.
Set X=3_
Output a byte from memory.
Immediate byte
Next instruction
This technique is also useful with the RETURN and DISABLE instructions, as discussed later in this
section.
Interrupt Service
The use of the COSMAC interrupt line involves special programming considerations_ The user should be
aware of the fact that an interrupt may occur between any two instructions in a program. Therefore, the
sequence of instructions initiated by the interrupt routine must save the values of any machine registers it
shares with the original program and restore these values before resuming execution of the interrupted
program_
R(1) must always be initialized to the address of the interrupt service program before an interrupt is
allowed_ Fig. 57 illustrates a hypothetical interrupt service routine. R(1) is initialized to 0055 before
permitting interrupt. R(2) is a stack pointer, i.e., it addressed the topmost byte in a variable-size data
storage area. This stack area grows in size as the pointer moves upward (lower memory addresses), much
like a stack of dishes on a table. Also like the dish stack, it shrinks as bytes are removed from the top. In the
interrupt service example of Fig. 57, the stack grew by two bytes as X,P and D were stored on it, and then
decreased to its original size when D and X,P were restored. Such a stack is sometimes referred to as a
"U FO" (Last·ln-First-Out) because the first item removed from the stack is the last one placed on it.
When bytes are to be stored into the stack, the pointer R(2) is first decremented to assure that it is
pointing to a free space. In the example shown, location OOFO may have been in use when the interrupt
occurred, so the pointer decrements to OOEF to store X,P. When bytes are no longer needed, they are re-
moved from the stack and the pointer is incremented.
The stack in Fig. 57 is used to store the values of X,P and D associated with the interrupted program. If
the interrupting program will modify any other registers (scratch pad or DF), their contents must also be
saved.
After these "housekeeping" steps have been completed, the "real work" requested by the interrupt
signal can be performed. This work may involve such tasks as transferring I/O bytes, initializing the DMA
pointer R(O), checking the status of peripheral devices, incrementing or decrementing an internal timer/
counter register, branching to an emergency power-shut-down sequence, etc.

Advertisement

loading