EasyManua.ls Logo

Radio Shack TRS-80 - Page 159

Radio Shack TRS-80
236 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...
3.
What other variables
are used by
the
subroutine
for
internal
calculations?
You
have
to
have a high need for
dangerous living
to use those
same
variable
names in
the main
part of the program.
Either
that, or
know
exactly
what
you're
doing. Best
to
change
the
program to avoid
re-using
a subroutine's
"internal
variables".
Type
in the square root
subroutine
exactly
as it's listed. There
is no
room
for error.
Now we need to interface
it (that's
high-powered
computer
jargon
to
impress
your
friends
with) to the resident
program
(more
jargon
get
the
idea?).
In
short, we
have
to
make
them
match up.
Make these changes in
the resident
program
:
40
X
=
A*A+B*B
j
GOSUB
30030
45 L
=
Y
and RUN.
If
your program
ran,
there was
a
slight
pause before
the Computer
came
back
with
the
answer:
A
B L
line
3#pp0
prevents the
Computer
from
crashing
into
the
subroutine
after
it
completes
your
main
program*
Atoays
tnsertthts
line when
using
.
subroutines.
;;:;:^
We send
controjto
3<M&30
rather
than
3#0i0
:-
because
J0010 and
30020
are
the
"non-working'
parts
of the
program
—they're
just
remarks
for
identification
only. ,
"
-
That's
because the
Computer
has to
do quite a bit of
thinking
to
compute
square
roots.
(See, computers
aren't so
smart after all!)
If
the program didn't
RUN, go
over the main
program
and the subroutine very
carefully.
Did
your GOSUB
statement
in Line
40
call
30030?
And
does
your
subroutine
really
begin
at
line
30030?
Here's why
we
changed
Line
40
and added
Line 45:
Line
40
has
two separate
statements.
X=A*A+B*B
gets our
input
variables
X ready.
GOSUB
30030
directs
the Computer to
the
subroutine
beginning
at Line
30030.
Lines
30010
and
30020
are remarks only. To speed
things
up,
we skip
over them.
The
Computer
executes
the
instructions
there
until it hits the
RETURN
statement
in Line
30080,
which
makes
it return
to
the
very
next
statement
in our
main
program,
Line
45.
Line
45 gives our hypotenuse
L
the
value
of
the
subroutine's
output
Y.
I
We
want
the
square root of
the
entire expression
A*A+B*B,
so we set it equai
to
X,
which is the
proper
input for
the subroutine.
157

Other manuals for Radio Shack TRS-80

Related product manuals