
50 Assembly Language Programming for the 68000 Family
tion, STOP, but if this instruction is used to terminate your program, the
microprocessor will literally stop and you will have to reboot (start from
scratch) your operating system. It is much better to return control such
that you can continue to issue system commands.
So that you can actually start to write programs using the input/output
procedures presented above, these must be included along with your
program and the shell. If you require one or more of these subroutines
in your program, just copy the appropriate source statements. You will
have to consult your system documentation to adapt these procedures for
other operating systems and/or assemblers.
Looping
With the instructions you have learned so far, it is possible to write a
few simple programs that perform addition and subtraction of a limited
number of values. To form the sum of 20 numbers entered from your
keyboard would take 20 lines of assembler source code just to obtain
these values. An additional 20 ADD instructions would be required as
well. If you desire to add up a larger number of values, you would soon
tire of all the typing needed to produce the source program. Consider
also that each assembly language instruction will take one or more words
of memory space when it is translated into machine language. Often it is
important to write a small program as well as an efficient one.
The solution to this problem is the use of a program loop. There
are many ways to write a program loop for the 68000 microprocessor.
The simplest type of program loop is the infinite program loop. While it
may seem of no value to write an infinite loop, if there is a method for
escaping the loop, it is often useful. You might like a program that repeats
itself over and over again for an arbitrary number of input data values.
This would eliminate the need to reinvoke the program for each new
value. The methods of escaping from an infinite loop will be discussed
in Chapter 5. For now, let us see how we can write one.
Execution normally passes from one instruction to the next. This is
known as sequential execution. The 68000 provides a special instruction
to alter the normal sequential program flow. The jump instruction, JMP,
provides the ability to transfer control to any instruction that has a label.
The following is a simple infinite loop:
OVER:
JMP
OVER
Kommentare zu diesen Handbüchern