EasyManua.ls Logo

Texas Instruments TI-99/4A - Page 133

Texas Instruments TI-99/4A
204 pages
Print Icon
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...
Subroutines
Introduction
Subroutines
may
be
thought
of
as
separate
self'contained
programs
within a
main
program.
They
usually perform a
certain
action.
such
as
printing
some
information,
performing
a calculation, or
reading
values into
an
array,
Putting
these actions into a
subroutine
allows
you to type
that
set
of
statements
only
once
and
then
perform
that
set
of
statements
from anyv.'"here in
the
program
with
a
GOSUB
statement.
The
GOSUB
statement
initially
behaves
like a
GOTO
statement.
It
causes
the
computer
to
jump
to the
line'number
listed. However,
subroutine
programming
gives the
computer
the
capability
to
"remember"
where
the
branch
occurred
in
the
main
program
and
return
to
that
point
when
it finishes
the
subroutine.
This
technique
requires
that
the
last
statement
in the
subroutine
be
a
RETURN
statement
Tht'
progr:lm
normally
has
either a
STOP
statement
or
some
other
unconditional
branching
statement
immediately
before
the
subroutines
so
that
the
computer
doesn't accidentally
"£'al1
into" the
subroutines
The
suhroutines
should
be
entered
only by a
GOSUB
instruction
and
may be
entered
at
any line-
number
within the subroutine,
The
example
on
the
right illustrates how
the
GOSUB
and
RETURN
statements
might be
arranged
in your
program,
The
program
begins
running
at
line 100.
At
line
300
it
skips
to
the
first
subroutine,
performs
lines
700
through
780,
and
returns
to line
310,
When it
reaches
line 400, it goes to the
second
subroutine.
performs
lines
900
through 980.
returns
to line 410,
and
continues
running,
At
line 450 it again goes to
subroutine
1, this time
entering
at Ime
750
and
continuing
to
the
RETURN,
Then
it goes
back
to the
main
program
at
line
460
and
continues
running.
At
line
480
it
again
jumps
to the first subroutine,
runs
lines 700 through
7HO.
returns
to line 490,
then
stops
runninj?; at line 600.
The
STOP
statement
in
line
600
keeps
the
computer
from
performing
the
subroutines
unless you specifically
direct
it
there
with a
GOSUB.
User's
Reference
Guide
Examples:
>N!::W
>100
REM
MAIN
PROGRAM
>300
GOSU8
700
>310
>400
GOSUB
900
>410
>
45
0
GOSU8
750
>460
>480
GDSUB
700
>490
-
>600
STOP
>700
REM
SUBROUTlNE1
>750
>780
RETURN
>900
REM
SU8RDUTINE2
>980
RETURN
>990
END
11,113

Other manuals for Texas Instruments TI-99/4A

Related product manuals