Motorola M68000 Betriebsanweisung Seite 66

  • Herunterladen
  • Zu meinen Handbüchern hinzufügen
  • Drucken
  • Seite
    / 256
  • Inhaltsverzeichnis
  • LESEZEICHEN
  • Bewertet. / 5. Basierend auf Kundenbewertungen
Seitenansicht 65
52 Assembly Language Programming for the 68000 Family
initializing Dn to 1 results in repeating the loop the maximum number
of times—65,536, to be exact. Only the low-order 16 bits of the register
are used as a counter. As a simple example, lets say you want to output
20 blank lines. You could call the newline subroutine 20 times by writing
20 lines of assembler source, or you could write the following three lines:
MOVE.W #19#D2 INITIAL VALUE IS COUNT-1
NEXT: JSR NEWLINE
DBRA D2,NEXT
You must be careful not to modify the contents of the Dn register within
the program loop, since it then would no longer represent the loop count
and would not yield the result desired. If you must use the Dn register
within the loop, you must save and restore it. You could move the contents
to another register or to a memory location. Heres how to do it with a
variable:
MOVE.W
#100,D1
NEXT: MOVE.W
D1,SAVED1
. <Use Dl>
MOVE.W
SAVED1,D1
DBRA D1 ,NEXT
SAVED1: DS.W 1
Recall from Chapter 3 that DS.W is not an instruction, but rather a
directive to reserve one or more words in memory. In this case one word
of uninitialized memory has been reserved at location SAVED1.
There is one restriction with the DBRA instruction that is not found
with the JMP instruction. With the JMP instruction the programmer can
transfer control to any distant label. In other words, there can be loops of
arbitrary size. Unfortunately, the DBRA instruction, and many others you
will discover, only allow transfer of control over a limited distance. This
distance is approximately plus-or-minus 32,768 bytes from the position of
the DBRA instruction itself. This distance can’t be represented as a fixed
number of instructions, because the number of bytes per instruction varies
with the particular instruction. It is a very rare occasion when a loop must
contain a greater number of instructions than this maximum. Fortunately,
the assembler tells the user if all the instructions do not fit into the loop.
In this case there are several methods to get around the problem. You
will have to read on to find out how.
Seitenansicht 65
1 2 ... 61 62 63 64 65 66 67 68 69 70 71 ... 255 256

Kommentare zu diesen Handbüchern

Keine Kommentare