Specifications

ReTurn from Sutwoutine
3.5&S
15
I
3 2
0
Operation: (reg) + (PC)
T (ret3
Condition Codes: not affected
Description: Loads content of reg into PC and pops the top element of the.
Processor stack into the specified register. Execution time for
RTS is
equal
to the basic instruction
time.
Return from a subroutine is typically made through the same register
that
was used in its call. Thus, a subroutine called with a JSR PC, dst
exists
with a RTS PC and a subroutine called with a JSR R5, dst, picks up param-
eters with addressing modes (R5)+, X(R5);or @X(R5) and finally exists
with a RTS R5.
Programming Examples of the Use of Subroutines-
1. Passing arguments in subroutine calls-The subroutine TOLER
checks each element in an array of unsigned integers to determine
whether any elements are outside specified limits. If all are within
tolerance, the value 0 is returned in the register RO. If TOLER find
an element out of tolerance, it returns the address of the bad
element + 2 in RO. The calling sequence for TOLER is:
JSR R5, TOLER
.
. WORD ARRAY
‘I
;address of array ts be
:checked (*WORD expres-
ision-defines a word equal
;to the value of the expres-
;sion)
. WORD -LENGTH
;minus # of items in array
/
. WORD HILIM
;upper limit of tolerance
. WORD LOLIM
;lower limit of tolerance
;subroutine returns here
;Tolerance Check-Array Elements Within Limits?
TOLER: , MOV (R5)+, RO
;get array address
MOV (R5)+, Rl
;get minus the length
MOV (R5)+, R2
:get high tolerance limit
MOV (R5)+, R3
;get low tolerance limit
TLOOP: MOV (RO)+;
CMP R4, R2
BHI TEXIT
CMP R4, R3
BLO TEXIT
INC Rl
;
BNE TLOOP
CLR RO
TEXIT: RTS R5
R4
;get next element of array
;check it against high limit
;leave routine if higher
;check it against low limit
;leave routine if lower
;increment count, check
;whether at end of array
;contihue if not at end yet
;exit with RO = 0 if all
ok
;return, RO holds poirter
:or 0
28