|
|
A simple example is shown below; the procedure and the call to it are shown
first in C (source code) and then in assembly. A more detailed, fully
documented example is shown in Appendix A.
In C:
:
:
proc (50,100); /* call to procedure 'proc' */
:
:
proc (x,y) /* function 'proc' */
int x,y; /* returns the sum of two integers */
{
return x+y;
}
:
:
In assembly:
:
LD1 50, gr26 ; load arg word 0 into gr26
** BL proc, gr2 ; branch (call) to 'proc'
LD1 100, gr25 ; <delay slot>
; load arg word 1 into gr25
:
:
proc: BV 0 (gr2) ; branch (return) back to caller
ADD gr26,gr25,gr28 ; <delay slot>
; add arguments,
; put result into gr28
:
** In instances where the target of the call is out of the range of the BL
(i.e. greater than 256K bytes), there will be a slightly different code
sequence. If this situation is identified at compile time, the compiler will
generate a three-instruction sequence (LDIL,BLE,COPY) that is guaranteed
to reach the target, instead of the BL. However, if the information is
not known until link time (the compiler has already generated the BL),
the BL will be linked to a "long branch stub" rather than to the actual
procedure. This "stub" is merely the same two-instruction sequence that would
have been used if the information had been known earlier.
|