Motorola M68000 Betriebsanweisung Seite 122

  • Herunterladen
  • Zu meinen Handbüchern hinzufügen
  • Drucken
  • Seite
    / 256
  • Inhaltsverzeichnis
  • LESEZEICHEN
  • Bewertet. / 5. Basierend auf Kundenbewertungen
Seitenansicht 121
108 Assembly Language Programming for the 68000 Family
reference. With call by reference, the address of the parameter is passed
on the stack. This allows the subroutine not only to access the parameter
in the caller’s domain, but actually to change its valuein other words,
the subroutine can have both input and output parameters. Call by value
only allows input parameters.
The PEA instruction discussed in Chapter 7 is used to pass the address
of each parameter that is to be a call by reference. Note that it is certainly
possible to have a mix of call by value and call by reference in the same
subroutine call. The only restriction is that both the caller and the callee
agree on the order and type of the parameters. Let’s say we want to
call subroutine ALPHA with the single parameter COUNT, using call by
reference. We would call ALPHA as follows:
PEA COUNT
JSR ALPHA
Furthermore, assume that subroutine ALPHA does something simple, like
adding 10 to its only parameter. Heres how we can do it:
ALPHA: MOVEA.L 4(SP),A0 GETS ADDRESS OP COUNT IN AO
ADD.L #10,(AO) ADD 10
RTS
Keep in mind that the data object to which the parameter points can
be as simple as a single integer or as complicated as the programmer
desiresan array of records, or even a record consisting of several arrays.
Anything that can be located by a single address can be passed as a
parameter using call by reference.
One problem still remains: the parameters are still on the stack when
the subroutine returns. The subroutine can’t pop the parameters, since
the return address is at the top of the stack. One method is to have the
caller clean up the stack. The caller has several choices as to what to do.
The caller can pop the parameters:
MOVE.L (SP)+,D0 PARM1
MOVE.L (SP)+,D0 PARM2
MOVE.L (SP)+,D0 PARM3
This technique is most useful when one or more parameters are return
values. The caller can also modify SP directly:
ADDA. L # 1 2 ,SP
Seitenansicht 121
1 2 ... 117 118 119 120 121 122 123 124 125 126 127 ... 255 256

Kommentare zu diesen Handbüchern

Keine Kommentare