Commodore 2001-8 User Manual page 93

Table of Contents

Advertisement

Chapter 8.-
USEOFTHE PET FOR MACHINE LANGUAGE PROGRAMMING
Machine language programs execute much faster than do BASIC programs which have to be interpreted
first then executed. On PET, machine language can be used to communicate with the user port, play
music, or write the screen memory with blinding speed. If you have never programmed the 6502
microprocessor, it is probably adviseable that you get hold of the two books mentioned in Chapter 1
before you proceed with this chapter.
In PET there are two ways to create a machine language program in memory and execute it. The first is by
BASIC. As previously discussed, there are two BASIC commands, PEEK and POKE which give equivalent
machine language operation relative to controlling input/output instructions or influencing or sampling
individual memory locations. The second method to program is by a monitor.
A monitor essentially has only three functions: examine and deposit bytes in memory, and branch to
execute code. These functions are available as PEEK, POKE and SYS in BASIC. The chief limitation of
BASIC is that all bytes must be converted to decimal before use. A monitor avaUable for PET allows one
to work entirely in hexadecimal notation but the 6502 does not care what base you work in because all it
sees is binary. The PET monitor does have some other useful features which we wilt discuss later.
MACHINE LANGUAGE PROGRAMMING FROM BASIC
It is possible to build into a string of memory locations by means of a POKE command, a set of
instructions which are a machine language subroutine which is usable by an individual program. To
implement these subroutines, there are four basic considerations: (1) what the subroutine is supposed to
do, (2) how to implement it, (3) where to put the program, and (4) how to communicate the subroutine from
BASIC. The decision on what the program is to do and how to implement it is left to the programmer and
the programming manual (6502).
To locate the code, you must decide whether you have a small program that is to be used only temporaril
or whether it is a program you want to have operational throughput the entire time the BASIC program is
operating in the machine.
To understand how best to keep the program in memory, we should review the memory map of the PET.
All the zero page programs address are consumed by the operating system and are usually being
changed throughout the programs. Between the normal use of stack and tape
1/0
corrections, all of page
1 is used. Page 2 has a series of variables which are again used throughout the program. However,
memory locations 634 through 1023 are used for the first and second cassette buffers. If a program is not
using tape I/O, then these areas will not be touched by BASIC.
If only the first cassette is used, the second cassette buffer is available. If both the cassettes are used
during the program, or if this area is not enough into which the user is to write some code, then the space
between the end of the BASIC program and where BASIC stores its variables is the space that is available
to the programmer. At any time during execution of the program, a PEEK into location 124 and 125
indicates the beginning location of the BASIC variables. Working back down these with a small safety
margin which is proportional to the amount of data space that is used in the program, is a memory area
which is not affected by BASIC during execution. These are memory locations which are counted by the
FRE statement. Once programs have been written and debugged, this space is as useful as are the
cassette locations.
The final problem is how to get the program into the memory location. Although by use of the machine
language monitor, machine language programs are loadable, this involves a two-step process for the
user. First, the machine language program must be loaded, followed by the loading of the BASIC
91

Advertisement

Table of Contents
loading

This manual is also suitable for:

Pet 2001-8

Table of Contents