MCS6500
Microcomputer Family
Programming Manual
APPENDIX G
DISCUSSION - INDIRECT ADDRESSING
The MCS650X microprocessors have a special form of addressing known
as Indirect. The writeup on Indirect addressing describes the basic
operation of Indirect.
It is the intent of this discussion to acquaint the user with some
of the uses and applications of Indirect addressing.
The Indirect address is really an address that would have been coded
in line as in the case of Absolute except for the fact that the address
is not known at the time the user writes the program. As has been indicated
several times in the basic body of the documentation, it is significantly
more efficient with the organization of the MCS650X to assign
addresses and implement them if the addressing structure is known. However,
that is not always possible to do. For instance, in order to minimize
the coding of a subroutine or general purpose set of coding, it is
often desirable to work with a range of addressing that is not possible
to cover in a normal index, or in the case of subroutine where it is necessary
for the addresses to be variable depending on which part of the whole
program called the address.
It is probably this discussion which best amplifies the need for
calculated addresses. It should be fairly obvious to the user that a
general purpose subroutine cannot contain the address of the operations.
Therefore, instead of having the instruction LDA followed by the value
that the programmer wants to load, in a subroutine it may be desirable to
do a Load A from a calculated or specified address.
The use of the Indirect Addressing Mode is to give the user a location
in Page Zero in which can be put the calculated address. Then the
subroutine instruction can call this calculated address using the form
Load A from an address pointed to by the next byte in program sequence.
The word "indirect" technically comes from the fact that instead of taking
the address which is immediately following the instruction, the next value
in program sequence is a pointer to the address.
The indirect pointer will be referred to from now on as IAL, because
it is a Zero Page address and, therefore, is a low order byte. The indirect
instructions are written in the form "Load A" followed by IAL.
IAL points to an address which had been previously stored into Page Zero.
This gives the user the flexibility of addressing anywhere in memory
with a calculated address. However, the real value of Indirect is not in
just having Indirect but having the ability to have Indirect modified.
This is the reason for which indirect indexed instruction is implemented
rather than straight indirect. An example of the indirect indexed in subroutining
is covered in Section 6.5, but it should be noted that the indirect
indexed instruction should be used whenever the user does not know
the exact address at time of compilation. Although there may be other interesting
and esoteric uses of the indirect index instruction, this is the
most common one.
The second form of indirect is very powerful for certain types of
applications. Chapter 11 shows the use of tables which have pointers and
the advantage of running down one table of pointers until a match is found
and then using the same index to address a second table to perform an operation.
This is the classical stack processor type of architecture but it
requires a special discipline at the time a program is originally defined.
Both the indirects require a concept of memory management that is not
obvious to the novice programmer.
The concept of indexed indirect is that memory has to be viewed as
a series of tables, in which access to one set of tables is accomplished
by indexing through a list of pointers. One set of tables might be searched
to perform some type of testing or operation. Then the same index is then
used to process another set of pointers. This concept is only applicable
to operations in which a variety of inputs are being serviced. A classical
application is when several remote devices are being managed by the same
control program. An example might be having three teletypes tied on to
a device, each teletype is being manually controlled and can be under control
of the user program. In this type of message handling environment,
the control program for the teletypes does nothing more than collect strings
of data from the input device and then performs operations on the string
upon seeing a control signal, usually a carriage return in this case of
the teletype. Because any one of the teletypes can be causing any one of
the series of operations, this program does not lend itself well to the
concept of absolute addressing. In fact, most of the subroutines which
deal with the individual processing should be written address independent.
This normally allows the addition of more devices without paying any penalty
in terms of programming. Therefore, this is a subroutine or nonabsolute
type of operation in which the indirect indexed would not apply because
each of the various operations use a function of position. In other words,
one can assign a series of tables that point at the teletype itself; another
set that points at an outgoing message stream and another set that
points to a series of tables which keep the status of the device. Each
of these pointers is considered to be an individual address at the beginning
of a string. Each string is a variable length. The teletype
strings may consist of a three character message followed by a character
return or a 40 character message followed by a character return. In the
MCS650X, this system will be implemented by means of developing a series
of indirect pointers. Each teletype will have an indirect pointer. Its
I/O port has another indirect pointer that points at the put-away string,
another one that points at the teletype message output string, another one
that points at its status table. If all of the teletypes work this way,
it can be seen that the coding to put data into the input message table
is the same for all the teletypes and is totally independent of the
teletype in which data is being stored.
The index register X serves as a control for the tables so that if all
tables were sequentially organized, X would point at the proper value for
each operation. A sample operation might be: read teletype three, transfer
the data to teletype three input register, update teletype three counter,
check to see that teletype three is still active, and decide whether or
not to return to signal teletype three back. The coding to perform each
of these operations would be exactly the same as coding for teletype two,
if the tables were organized such that X was an index register for the
pointers.
This is the type of string manipulation application for which indexed
indirect was designed and only when a program can be organized for this
technique is the indirect used to its maximum potential. The advantages
for organizing for this type approach when the problem requires string
manipulation is significant; the comprehensive I/O program is roughly
one half the memory and one fourth the execution time of several other
microprocessors which do not have this indexed indirect feature.