Motorola M68000 Betriebsanweisung Seite 121

  • Herunterladen
  • Zu meinen Handbüchern hinzufügen
  • Drucken
  • Seite
    / 256
  • Inhaltsverzeichnis
  • LESEZEICHEN
  • Bewertet. / 5. Basierend auf Kundenbewertungen
Seitenansicht 120
Subroutines 107
HIGH RDDRESS
LOW ADDRESS
of course, SP. After the call, SP is pointing at the 32-bit return address value.
The first parameter is located at 4(SP) (assuming that the parameters were
pushed onto the stack in reverse order). Where would the second parameter
be? Well, that depends on the size of the first parameter. If the first
parameter is a longword, as in this example, then the second parameter is at
8(SP). Each of the other parameters can be found in a similar manner.
I should refresh your memory concerning register A7 (SP), the stack
pointer. When postincrement or predecrement addressing are used with a
byte-sized operand, SP is always modified by 2, even though the operand
is a byte. This is so the stack can always be aligned on an even-word
boundary. You should remember this fact if you pass a byte parameter on
the stack—always count it as two bytes. If you use a byte-sized instruction
for both the push and the pop, everything will work out okay.
The following instructions will obtain the three parameters from the
above example and place them into registers DO, Dl, and D2:
MOVE.L 4(SP),D0 PARM1
MOVE.L 8(SP),D1 PARM2
MOVE.L 12(SP),D2 PARM3
Of course, the parameters do not have to be moved to registers to be
used; they can be referenced directly.
This very common and simple method of passing parameters is re
ferred to as call by value. The actual value of the parameter is placed
on the stack. There are some limitations to this technique. First, it is only
practical to pass byte, word, or longword arguments on the stack. What
if we want to pass an entire array? Second, the subroutine has no way to
change the actual parameter; it can only change the copy it has on the
stack. Both of these limitations can be overcome by the use of a call by
PARM3
PARM2
PftRMl
SP
RETURN ADDRESS
Seitenansicht 120
1 2 ... 116 117 118 119 120 121 122 123 124 125 126 ... 255 256

Kommentare zu diesen Handbüchern

Keine Kommentare