Casio CFX-9800G-w Owners Manual - Page 172

Using, Subroutines, Important, Array, Memory

Page 172 highlights

With this program, the first statements specify the unit of angular measurement and clear T to 0. Then the initial velocity is prompted for V and the angle is prompted for S. Lbl 1 identifies the beginning of the repeat calculation. The value stored in. T is incremented by Isz T, and in this program the lsz command is used only for incrementation, without any comparison or decision being performed. Each time T is incremented, the formula is calculated and the altitude is displayed. 12-9 Using Subroutines Up to this point, all of the programs we have seen were contained in a single program area. You can also jump between program areas, so that the resulting executionis made up of pieces in different areas. In such a case, the central program from which other areas are jumped to is called a "main routine". The areas jumped to from the main routine are called "subroutines". Note that you can use either another program stored in the program area or a program stored as a File Editor tile as a subroutine. Main Routine PO r- P3 Subroutines Prog 3 ,,,, ,- 1.- '39 Prog 2 ..„,_,-- Prog 4 "e " ---- Prog 8"-4-----....._ Pro,g 9.... ,,,_ / \_ / \ / • / Level I Level 2 Level 3 Level 4 To ump to a subroutine, use Prog (input using 131E ZEID(Prg)) followed by a program area name (0 to 9, A to Z, r, or 0) or the name of a File Editor file. Examples Prog 2 - Jumps to the program stored in program area number 2. Prog ABC - Jumps to the program stored in a file named "ABC". After the jump to the program you specify, execution continues from the beginning of the subroutine. When end of the subroutine is reached, execution returns to the statement following the Prog command that initiated the subroutine. You can jump from one subroutine to another, a procedure that is called "nesting". You can nest up to a maximum of 10 levels, and an error will- occur (Ne ERROR) if you try to nest an 11th time. If you try to jump to a program area that does not contain a program, an error message (Go ERROR) will appear on the display. Important •The Goto command does not jump between program areas. A Goto command jumps to the label (Lbl) located inside the same program area. -308 - •Subroutines Save Memory Note the following two programs. PO Fix, 3, :, ?, A, :, 2, x,C, 3, x, C . 2, e, 3, x, A, A , 3 P1 Fix, 3, :, ?, A, :, T, 3, x, A, x2,.4, V-, 2, +, 1 2 x A, A, 3 23 bytes 22 bytes If we input these two programs separately, they require a total of 45 bytes. But note that the underlined portions of these two programs are identical. This means that these parts can be stored as subroutines and called by both of the programs. If we use subroutines, we get the following results. Subroutines P9 Fix, 3 A, : , J- , 3, x,. A, x2 P8 C, 2, =, 3, x, A, A, 3 12 bytes. 8 bytes Main routines PO Prog, 9, :, Ans, x, 2, A, Prog, 8 P1 Prog, 9, A, Prog, 8, Ans, ÷, 4 9 bytes 9 bytes As you can see, the number of bytes required to store the two programs and the subroutines is 38, for a saving of 7 bytes. When you execute the program in program area 0, it immediately jumps to P9 and executes the contents of that program area. At the end of P9, execution returns to PO where the result produced by the subroutine in P9 is multiplied by 2 and then displayed. After you press the El key, execution jumps to P8, where the remainder of the program is executed. With the main routine in program area P1, execution jumps immediately to program area P9. At the end of P9 execution returns to P1 where the P9 result is displayed. When you press EL execution jumps again to P8. At the end of P8, execution returns to P1, where the result produced by P8 is divided by 4 and displayed. 12-10 Using Array Memory In addition to the individual value memories, the unit gives you array memory capabilities. Note the following. Value Memories A B C Array Memories A[0] B[ - 1] A[1] B(0] At2I B[1] Note *You cannot use r or 0 value memory as array memory. -309-

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206

With
this
program,
the
first
statements
specify
the
unit
of
angular
measurement
and
clear
T
to
0.
Then
the
initial
velocity
is
prompted
for
V
and
the
angle
is
prompted
for
S.
Lbl
1
identifies
the
beginning
of
the
repeat
calculation.
The
value
stored
in
.
T
is
incremented
by
Isz
T,
and
in
this
program
the
lsz
command
is
used
only
for
incrementation,
without
any
comparison
or
decision
being
performed.
Each
time
T
is
incremented,
the
formula
is
calculated
and
the
altitude
is
displayed.
12-9
Using
Subroutines
Up
to
this
point,
all
of
the
programs
we
have
seen
were
contained
in
a
single
program
area.
You
can
also
jump
between
program
areas,
so
that
the
resulting
execution
is
made
up
of
pieces
in
different
areas.
In
such
a
case,
the
central
program
from
which
other
areas
are
jumped
to
is
called
a
"main
routine".
The
areas
jumped
to
from
the
main
routine
are
called
"subroutines".
Note
that
you
can
use
either
another
program
stored
in
the
program
area
or
a
program
stored
as
a
File
Editor
tile
as
a
subroutine.
Main
Routine
Subroutines
PO
r-
P3
Prog
3
,,,
, ,-
1
.
-
'39
Prog
4
Prog
8
--
Prog
9
P
rog
2
..„,_,--
"
e"
-
---
"
4--
--
.....
_
,
....
,,,_
/
\_
/
\
/
/
Level
I
Level
2
Level
3
Level
4
To
ump
to
a
subroutine,
use
Prog
(input
using
131E
ZEID(Prg))
followed
by
a
program
area
name
(0
to
9,
A
to
Z,
r,
or
0)
or
the
name
of
a
File
Editor
file.
Examples
Prog
2
Jumps
to
the
program
stored
in
program
area
number
2.
Prog
ABC
Jumps
to
the
program
stored
in
a
file
named
"ABC".
After
the
jump
to
the
program
you
specify,
execution
continues
from
the
beginning
of
the
subroutine.
When
end
of
the
subroutine
is
reached,
execution
returns
to
the
statement
following
the
Prog
command
that
initiated
the
subroutine.
You
can
jump
from
one
subroutine
to
another,
a
procedure
that
is
called
"nesting".
You
can
nest
up
to
a
maximum
of
10
levels,
and
an
error
will
-
occur
(Ne
ERROR)
if
you
try
to
nest
an
11th
time.
If
you
try
to
jump
to
a
program
area
that
does
not
contain
a
program,
an
error
message
(Go
ERROR)
will
appear
on
the
display.
Important
•The
Goto
command
does
not
jump
between
program
areas.
A
Goto
command
jumps
to
the
label
(Lbl)
located
inside
the
same
program
area.
—308
•Subroutines
Save
Memory
Note
the
following
two
programs.
PO
Fix,
3,
:,
?,
A,
:,
2,
x,C,
3,
x,
C
.
2,
e,
3,
x,
A,
A
,
3
P1
Fix,
3,
:,
?,
A,
:,
T,
3,
x,
A,
x
2
,.4,
V
,
2,
+,
1
2
x
A,
A
,
3
23
bytes
22
bytes
If
we
input
these
two
programs
separately,
they
require
a
total
of
45
bytes.
But
note
that
the
underlined
portions
of
these
two
programs
are
identical.
This
means
that
these
parts
can
be
stored
as
subroutines
and
called
by
both
of
the
programs.
If
we
use
subroutines,
we
get
the
following
results.
Subroutines
P9
Fix,
3,
:
,
?,
-?,
A,
:
,
J
-
,
3,
x,.
A,
x
2
12
bytes.
P8
C,
2,
=,
3,
x,
A,
A,
3
8
bytes
Main
routines
PO
Prog,
9,
:,
Ans,
x,
2,
A,
Prog,
8
9
bytes
P1
Prog,
9,
A,
Prog,
8,
Ans,
÷,
4
9
bytes
As
you
can
see,
the
number
of
bytes
required
to
store
the
two
programs
and
the
subrou-
tines
is
38,
for
a
saving
of
7
bytes.
When
you
execute
the
program
in
program
area
0,
it
immediately
jumps
to
P9
and
exe-
cutes
the
contents
of
that
program
area.
At
the
end
of
P9,
execution
returns
to
PO
where
the
result
produced
by
the
subroutine
in
P9
is
multiplied
by
2
and
then
displayed.
After
you
press
the
El
key,
execution
jumps
to
P8,
where
the
remainder
of
the
program
is
ex-
ecuted.
With
the
main
routine
in
program
area
P1,
execution
jumps
immediately
to
program
area
P9.
At
the
end
of
P9
execution
returns
to
P1
where
the
P9
result
is
displayed.
When
you
press
EL
execution
jumps
again
to
P8.
At
the
end
of
P8,
execution
returns
to
P1,
where
the
result
produced
by
P8
is
divided
by
4
and
displayed.
12-10
Using
Array
Memory
In
addition
to
the
individual
value
memories,
the
unit
gives
you
array
memory
capabili-
ties.
Note
the
following.
Value
Memories
A
B
Array
Memories
A[0]
B[
-
1]
A[1]
B(0]
C
At2I
B[1]
Note
*You
cannot
use
r
or
0
value
memory
as
array
memory.
—309—