EasyManua.ls Logo

Radio Shack TRS-80 Model III - Page 202

Radio Shack TRS-80 Model III
274 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
TRS-80
MODEL
III
Making
the USR call
At the point in
your
BASIC program
where you
want to call the
subroutine, insert
a
statement
like
X
=
USR(N)
where
N can be 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
consider
it 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 your
USR routine where
you want to
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 argument
to
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 your
USR routine .
:
CALL0A7FH
This
loads the
argument
N into the HL
register pair as
a two-byte signed
integer.
Returning
an argument
from
the USR routine
To return
an integer
value 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
your routine:
JP 0A9AH
Control
will pass
back
to
your
program,
and the integer in
HL will replace
USR(N).
For
example
,
if
the call was
X
=
USR(N)
Then
x
will
be given the
value in HL.
USR routines
are automatically
allocated up to 8 stack
levels or
1 6 bytes
(a
high
and
low
memory
byte for
each stack level)
. If you need
more stack
space
,
you
can
save
the BASIC stack
pointer
and set
up
your
own stack.
See SYSTEM,
PEEK,
and POKE.
Also see
the Technical
Information
Chapter in
the Owners Section
.
192

Other manuals for Radio Shack TRS-80 Model III

Related product manuals