c64-users_guide-03-beginning_basic_programming.pdf
(
1099 KB
)
Pobierz
Up to now we've performed
some simple
single line of instructions
into the computer.
operations
by entering
a
Once .:j:aIlI~U. was de-
immediately.
pressed,
the operation
that we specified was performed
mode.
This is called the
IMMEDIATE
or CALCULATOR
But to accomplish
anything significant,
we must be able to have the
computer
operate with more than a single line statement.
A number of
statements
combined
together
is called a PROGRAM and
use the full power of the Commodore
64.
To see
this:
how easy
it is to write
your first Commodore
allows
you to
try
Clear the screen by holding the
ItJ.~fj:[.],',I:I
key.
_
64 program,
key, and then depressing
the
Type NEW and press .~j:alll=!/.. (This just clears out any numbers that
might have been left in the computer from your experimenting.)
Now type the following exactly as shown (Remember to hit .:j:alll~j/.
after each line)
1121
2121
?"CONNODORE
64"
GOTO
1121
f
I
.
Now, type RUN and hit .~j:alll:j/.-watch
what happens. Your screen
will come alive with COMMODORE 64. After you've finished watching
the display, hit .~m/'I.'t(ll:l to stop the program.
A number of important concepts were introduced in this short pro-
gram that are the basis for all programming.
Notice that here we preceded each statement with a number. This
LINEnumber tells the computer in what order to work with each state-
ment. These numbers are also a reference point, in case the program
needs to get back to a particular line. line numbers can be any whole
number (integer) value between 0-63,999.
1~ PRINT "COMMODORE
64"
r
L
STATEMENT
LINE
NUMBER
32
I
It is good programming practice to number lines in increments of
10-in
case you need to insert some statements later on.
Besides PRINT, our program also used another BASIC command,
GOTO. This instructs the computer to go directly to a particular line and
perform it, then continue from that point.
[
HI' PRINT "COMMODORE
64"
2" GOTO 1"
In our example, the program prints the message in line 10, goes to
the next line (20), which instructs it to go back to line 10 and print the
message over again. Then the cycle repeats. Since we didn't give the
computer a way out of this loop, the program will cycle endlessly, until
we physically stop it with the .:ml' u.UI key.
Once you've stopped the program, type: LIST. Your program will be
displayed, intact, because it's still in the computer's memory. Notice,
too, that the computer converted the? into PRINTfor you. The program
can now be changed, saved, or run again.
Another important difference between typing something in the im-
mediate mode and writing a program is that once you execute and
clear the screen of an immediate statement, it's lost. However, you can
always get a program back by just typing LIST.
By the way, when it comes to abbreviations don't forget that the
computer may run out of space on a line if you use too many.
33
EDITING TIPS
If you make a mistake on a line, yoju have a number
options.
of editing
1. You can retype a line anytime, and the computer will automatically
substitute the new line for the old one.
2. An unwanted line can be erased by simply typing the line number
and
.II.IIIII~.
.
3. You can also easily edit an existing line, using the cursor keys and
editing keys.
Suppose you made a typing mistake in a line of the example. To
correct it without retyping the entire line, try this:
Type LIST, then using the
and 11..m."I'.~1keys together
move the
cursor up until it is positioned on the line that needs to be changed.
Now, use the cursor-right key to move the cursor to the character yo'u
want to change, typing the change over the old character. Now hit
.~I:lIII:I~. and the corrected line will replace the old one.
If you need more space on the line, position the cursor where the
space is needed and hit IDIIiI and .1~1o"t1J.4I'I~. same time and a
at the
space will open up. Now just type in the additional information and hit
.:I:lIIIII~.
.
Likewise, you can delete unwanted characters by placing the
cursor to the right of the unwanted character and hitting the .1~Io"tIJ.4I'I~.
key.
To verify that changes were entered, type LIST again, and the cor-
rected program will be displayed! And lines don't have to be entered in
numerical order. The computer will automatically place them in the
proper sequence.
Try editing our sample program on page 33 by changing line 10 and
adding a comma to the end of the line. Then RUN the program again.
HII
PRINT
"COMMODORE",
..
~
DON'T FORGET MOVETHE
TO
CURSOR PAST LINE 20 BEFORE
YOU RUN THE PROGRAM.
VARIABLES
Variables are some of the most used features of any programming
language, because variables can represent much more information in
the computer. Understanding how variables operate will make comput-
ing easier and allow us to accomplish feats that would not be possible
otherwise.
34
I
COMMODORE
COMMODORE
COMMODOR
COMMODORE
COMMODORE
COMMODORE
COMMODORE
COMMODORE
COMMODORE
COMMODORE
COMMODORE
COMMODORE
COMMODORE
BREAK IN 10
READY
.
COMMODORE
COMMODORE
COMMODORE
COMMODORE
COMMODORE
COMMODORE
~M~O~E
COMMODORE
COMMODORE
COMMODORE
COMMODORE
COMMODORE
COMMODORE
COMMODORE
COMMODORE
COMMODORE
COMMODORE
COMMODORE
COMMODORE
COMMODORE
COMMODORE
COMMODORE
COMMODORE
COMMODORE
COMMODORE
COMMODORE
COMMODORE
COMM06oRE
COMM06oRE
COMM06oRE
COMMODORE
COMMODORE
COMMODORE
COM~J~ORE
COMMODORE
COMMO~ORE
COMMODORE
COMMOBORE
COMMOIDORE
Imagine a number of boxes within the computer that can each hold a
number or a string of text characters. Each of these boxes is to be
labeled with a name that we choose. That name is called a variable
and represents the information in the respective box.
For example, if we say:
113
X% = 15
20 X = 23.5
313X$ = "THESUMOF X%+X = "
The computer might represent
X%
X
X$
15
23.5
THE SUM OF X% +X
the variables
like this:
A variable name represents the box, or memory location, where the
current value of the variable is stored. As you can see, we can assign
either an integer number, floating point number, or a text string to a
variable.
The % symbol following a variable name indicates the variable will
represent an integer number. The following are valid integer variable
names:
35
Plik z chomika:
TeslaXOS
Inne pliki z tego folderu:
c64-programmers_reference_guide-05-basic_to_machine_language.pdf
(10485 KB)
c64-programmers_reference_guide-07-appendices.pdf
(9680 KB)
c64-programmers_reference_guide-03-programming_graphics.pdf
(6872 KB)
c64-programmers_reference_guide-02-basic_language_vocabulary.pdf
(5747 KB)
c64-users_guide-09-appendices.pdf
(7218 KB)
Inne foldery tego chomika:
Pliki dostępne do 01.06.2025
Pliki dostępne do 19.01.2025
Aktywator Windows XP
Apollo 11 Source Code
baza leków
Zgłoś jeśli
naruszono regulamin