EasyManua.ls Logo

Radio Shack TRS-80

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...
Chapter
25
Advanced
Subroutines
Back in
Chapter
15,
we touched on the subject
of
subroutines.
We even "called"
one, just
to get the hang of it. But then we rewrote
that
subroutine
as a part of our
main program,
and got the
same
results just as easily. So what's
so
special about
subroutines?
That's what
this
chapter is about.
To refresh your memory:
A
subroutine
is a special
kind
of program
which the
Computer
ignores
until a GOSUB statement calls for
it. After executing
the subroutine, the
Computer
automatically RETURNs program control
to a
point
right
after
the GOSLJB
statement.
So
no matter
how many different times and places
your program "branches"
to a subroutine,
program
control
always
returns to the point where
it left off.
An important
application of subroutines is
the
calling of special
routines
that allow
the
Computer
to do things that it
couldn't
do otherwise. Take
square roots, for example.
Many
larger
forms of BASIC
(like
Radio Shack LEVEL
II
BASIC) will let
you compute
JX
simply by
using
the
statement,
Y
=
SQR(X),
LEVEL
I BASIC
doesn't
have this ability,
so
we need to add a fairly simple
program
to accomplish the
same
thing
a subroutine.
There are many other
special
routines that we
can call to make the
computer "educated
beyond
its
intelligence".
Most are very
mathematical,
and
are
only
for rather
special
applications.
But when they
are
needed, they are
badly
needed. Even if
you don't
think
you'll have use of them,
go through this lesson
anyway.
You'll probably find
some
special
program in a magazine
or
elsewhere
that you desperately want to run on your
Computer
but
it needs
a
trigonometric,
logarithmic,
or
other higher-math function.
You
don't have
to like or even understand
these
special routines to be
able
to use them
like
an expert. Give
it a good shot.
Whatever
became
of
good old Pythagoras
and who cares?
Remember
the fun days
in
geometry and
algebra
class
when you were engaged in such
excit-
ing
things as trying to
find
the
length of
the
hypotenuse
of a right triangle
when
the
lengths
of
the other two sides
were
known? Welcome
back!
The
Pythagorean
rule says,
"The length
of
the hypotenuse
is equal
to
the
square
root
of the sum
of
the squares of the remaining
two
sides."
No
wonder
you
took
ceramics
instead.
We know all
about equations now, though,
so
we can
state
it much
more
simply:
L=
v/A
2
+
B
2
"ME?
A SUB?"
Functions
like
SQR
are
called intrinsic
(built-in)^;
when
they are available
directly, without
the
need
for
calling
a special
subroutine.
ABS, INT
and;
,
END are
a
few
of
the
intrinsic
functions
available
in.
LEVJL.I
BASIC.,
. .
.
;
155

Other manuals for Radio Shack TRS-80

Related product manuals