Sharp OZ-707 Operation Manual - Page 37

Debugging

Page 37 highlights

4. DeBUGGING er entering a new BASIC program, it often does not work th~ first Ae. Even if you are simply entering a program that you know IS trect, such as those provided in this manual, it is common to make deast one typing error. It may also contain at least one logic error as ~II . \ "owing are some general hints on how to find and correct your tors. Suppose you run your program and get an error message: •Go back to the PRO mode and use the C2SJ or I3ZJ key to recall the line with the error. The cursor will be positioned at the place in the line where the Card became confused. If you cannot find an obvious syntax error, the problem ma~ lie wi~h ahe values that are being used. Check the values of the vanabies In either the RUN or PRO mode by entering the name of the variable and pressing the IENTER I key. Ippose you run the program and do not get an error message, but aprogram does not do what you expect. 1 Check through the program line by line using LIST and the C2SJ 'and [YJ keys to see if you have entered the program correctly. It is surprising how many errors can be corrected by just taking another look at the program. Think about each line as you go through the program as if you were :the Card. Take sample values and try to apply the operation in each line to see if you get the result that you expected. Insert one or more extra PRINT statements in your program to :display key values and key locations. Use these to isolate the parts of the program that are working correctly and the location of the error. This approach is also useful for determining which parts of a program have been executed. You can also use STOP to temporarily halt execution at critical points so that several variables can be examined. 62 4. Use TRON (TR~~ ON) and TROFF (TRace OFF), either as direct tchorm~mugahn.Idnsdl.Vo~ldWui~t1hlli~nethse. program to trace the flow of the Stop to examine the contents of program critical van~~les at c~clal points. This is a very slow way to find a problem but It IS sometimes the only way. ' tNhoatmdaotetesrnhootwdocaqr~el!tuel you are, what you eventually you will create a expect it to. To isolate the program problem, BASIC has a speCial method of executing programs known as the "Trace" mode. w!IRSit~hOUi~nNdaa('TspRraaoc~dr~iraemOc.Nt ~)csosemtadmrtasasnTdarad(~IinereRmcUtocNdoemm. mTohdaeen)dT,oRrTOiRtNOmNianysintbrfueocretmiomsnbtehmdeadyCedabred that tracing IS required during the execution of all subsequent programs..The programs to be traced are then started in a normal manner, with a GOTO or RUN command. If TRON is. used as a statement, it will initiate the Trace mode only when the line containing it is executed. If. for some reason, that line is never reached, Trace mode will remain inactive. Debugging Procedures 1. Set the computer to RUN mode. 2. Enter TRON IENTER I to specify the trace mode. 3. E.nter RUN IENTER Ito execute the program. The line number will be dlspla~ed .at above right of the display for about 0.5 second after each line IS executed. 4. Press the 00 ~ey .when the desired line number is displayed. The GSJ break ~meyestsoagd.iespISlaydisthpelalyaesdt and execution is interrupted. Press statement executed. To resume the execution,. press t~e I~HI': 1l3ZJ keys or enter CONT [ENTER 1. IHNoPw~eTvecr~, mIfmeaxnedc,utjiuosnt IS Interrupted during data entry using the press the IENTER I key as for usual program continuation. CXJ 5. ~ Pressktehye Will key to move to the line to be checked. Holding execute the program step by step. Releasing the the key Will stop program execution. 63

  • 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

4.
DeBUGGING
er entering a new BASIC program,
it
often does not work
th~
first
Ae.
Even if you are simply entering a program that you know
IS
trect, such as those provided in this manual, it
is
common
to
make
deast one typing error. It may also contain at least one logic error as
~II
.
\
"owing are some general hints on how to find and correct your
tors.
Suppose you
run
your program and get
an
error message:
Go
back to the PRO mode and use the
C2SJ
or
I3ZJ
key
to
recall
the
line with the error. The cursor will be positioned at the place
in
the line where the Card became confused.
If you cannot find an obvious syntax error, the problem
ma~
lie
wi~h
ahe values that are being used. Check the values of the
van
abies
In
either the RUN or PRO mode by entering the name of the variable
and pressing the
I
ENTER
I
key.
Ippose you run the program and do not get
an
error message, but
a
program does not do what you expect.
1
Check through the program line by line using LIST and the
C2SJ
'and
[YJ
keys to see if you have entered the program correctly. It is
surprising how many errors can be corrected by just taking another
look at the program.
Think about each line
as
you go through the program as if
you
were
:the Card. Take sample values and try to apply the operation in each
line to see if you get the result that you expected.
Insert one or more extra PRINT statements in your program
to
: display key values and key locations. Use these to isolate the parts
of the program that are working correctly and the location of the
error. This approach
is
also useful for determining which parts of a
program have been executed. You can also use STOP to
temporarily halt execution at critical points so that several variables
can be examined.
62
4.
Use TRON
(TR~~
ON) and TROFF (TRace OFF), either as direct
comman.ds
.o~
Withl~
the program
to
trace the flow of the program
thr~ugh
IndlVldu~1
lines. Stop
to
examine the contents of critical
van~~les
at
c~clal
points. This
is
a very slow way
to
find a problem
but It
IS
sometimes the only way.
'
No matter how care!ul you are, eventually you will create a program
that does not do
q~lte
what you expect it to. To isolate the problem,
BASIC has a
speCial
method of executing programs known
as
the
"Trace" mode.
!RON
(TRac~
ON) starts
Tra~e
mode. The TRON instruction may
be
IS~U~d
as a direct command
(In
RUN
mode) or it may be embedded
within a
'pro~ram.
~sed
as a direct command, TRON informs the Card
that tracing
IS
required during the execution of all subsequent
programs
..
The programs to be traced are then started in a normal
manner, with a GOTO
or
RUN command.
If TRON
is.
used as a statement, it will initiate the Trace mode only
when the line containing it
is
executed. If. for some reason, that line
is
never reached, Trace mode will remain inactive.
Debugging Procedures
1.
Set the computer to RUN mode.
2.
Enter TRON
I
ENTER
I
to specify the trace mode.
3.
E.nter
RUN
I
ENTER
I
to execute the program. The line number will
be
dlspla~ed
.at above right of the display for about 0.5 second after
each line
IS
executed.
4. Press the
00
~ey
.when the desired line number is displayed. The
break
messag.e
IS
displayed and execution is interrupted. Press the
GSJ
~ey
to
display the last statement executed.
To
resume
execution,. press
t~e
I
~HI':
1l3ZJ
keys or enter CONT
[ENTER
1
.
However,
If
execution
IS
Interrupted during data entry using the
INP~T
c~mmand,
just press the
I
ENTER
I
key
as for usual program
continuation.
5.
Press the
CXJ
key to move
to
the line to
be
checked. Holding the
~
key
Will
execute the program step by step. Releasing the key
Will
stop program execution.
63