TRS-SO
MODEL
III
Making the USR call
Atthe point in yourBASIC programwhere you want to call the subroutine, insert a
statementlike
X USR(N)
where N canbe an expression and must have a value between 32768 and
+32767 inclusive. This argument,
N,
can be used to pass a value to your routine
(see below)
or
you can simply considerit a dummy argument and not use it at all.
When
BASIC encounters your X = USR(N) statement, it will branch to the address
stored at
16526-16527.
At
the point in yourUSR routine where you wantto
return
to the BASIC program, insert a simple RET instruction- unless you want to return a
value to
BASIC, in which case, see below.
Passing
an
argumentto the USR routine
If
you want to pass the USR(N) argument to your routine, then include the following
CALL instruction at the beginning
of
yourUSR routine.:
CALLOA7FH
This loads the argument N into the
HL
registerpair as a two-byte signed integer.
Returning
an
argument
from the USR routine
To
return an integervalue to the USR(N) function, load the value (a two-byte signed
integer) into
HL
and place the following
jump
instruction at the end
of
yourroutine:
JP
@A9AH
Control will pass
back
to yourprogram, and the integer in HL will replace USR(N).
For
example,
if
the call was
X=
USR(N)
ThenX will be giventhe value in
HL.
USR routines are automatically allocated up to 8 stacklevels
or
16
bytes (a high and
low memory byte for each stacklevel).
If
you needmore stack space, you can save
the
BASIC stackpointerand set up your
own
stack. See SYSTEM, PEEK, and POKE.
Also see the Technical Information Chapterin the Owners Section.
8/8