You are here

PROGRAMMING THE 6502

Author(s): 

Rodney Zaks
Reviewed by William K Nonidez*

Note: This article was scanned using OCR from the Spring 1995 CCCE Newsletter. Please contact us if you identify any OCR errors.
 
As the new fast generation of microcomputers begin to invade our lives with their vastly enhanced computational and graphics capabilities, it is a temptation to shove our older systems over to a quiet part of the lab and quietly let them die. This may well be a blessing for those of us in education because, if we are clever, we can beg these machines from our more aftluent colleges and use them in our own labs and classrooms to teach the fundamentals of computers and microprocessors.
 
Machines based upon the 6502 microprocessor are ideal for this purpose due to the relative simplicity of 6502 architecture and to the openness of most manufacturers in documenting the architecture of their machines. The most prevalent example of such an instrument is the Apple II series, which is shipped with a detailed reference manual which explains in quite readable detail how the instrument works and even includes detailed ROM listings and entry points. Although these manuals contain sections on the 6502 instruction set and brief descriptions of their structure, most of us can only make sense of this material after we have a sufficient background in the basics. I can strongly recommend Programming the 6502 for obtaining this background.
 
Programming the 6502 is divided into eleven chapters and nine appendices. Chapter 1 is the obligatory chapter on basic concepts which must be understood before continuing with the rest of the book. These topics include basic elements of programming, information representation and flowcharting. Zacks' treatment of this topic makes the entire book worthwhile because (Wonder of Wonders!) he has included examples and exercises which appear in the text directly after the explanation. Since the answers and explanations appear at the end of the text you can read this chapter and test yourself on the concepts presented as you go.
 
Programming the 6502 requires a thorough understanding of how the various registers in the microprocessor are organized and exactly what is the function of each. Chapter 2 explains the organization of the 6502 and, in general terms, how it works in enough detail to make programming possible. The minute detail which would lead to a deeper understanding is mercifully omitted. Chapter 3 presents the fundamental techniques necessary for writing a machine language program. Additionally register management, loops and subroutines are discussed. The author uses very simple programs as examples, such as addition and subtraction in both binary and BCD mode, for this purpose as well as more complicated programs such as 16-bit multiplication and division. Only the most simple addressing is used in these programs since the concept is discussed in detail in a later chapter. Again the author makes use of highly instructive exercises to insure that the reader understands vital concepts as he moves through the text.
 
Chapter 4 is an exhaustive summary of the 6502 instruction set. The first part of the chapter classifies the instructions which follow into five classes and discusses each class in detail. Then each instruction is explained in detail as well as how they may affect flags or can be utilized with various modes of address. I would suggest that·the reader go over this chapter the first time with the object of obtaining an overview of the instruction set since the comments about addressing and flags will make little sense at this time. Then as he proceeds through the book he can come back to this chapter for learning greater detail about instructions as needed.
 
Addressing techniques is the hardest topic, in my opinion, to be mastered in machine language programming. Zaks patiently goes through the various modes available on the 6502 with examples of each in Chapter 5. I found the use of diagrams called data paths extremely helpful in this section (once I figured them out). Again this is a chapter whose broad concepts should be appreciated on a first reading. During actual programming attempts the reader will have to return to this section many times to pick up the details necessary for successful program writing.
 
Chapters 6 and 7 are concerned with the problem of microprocessor communication with the external world. The 6502, since it is memory mapped, treats memory and 110 ports alike and considers both to be memory. In other words the 6502 does not have separate pins for a read and write signal as do the ZSO or 8080. A write operation to the proper memory location can serve as an output operation, a read operation from the proper memory location can serve as an input operation. This feature makes the 6502 particularly simple to interface. Zaks discusses in Chapter 6 both the simple task of communication with common 1/0 devices as well as the more complicated task of dealing with several of these devices through interrupts. The reader should be cautioned here that various microcomputers which utilize the 6502 have been designed with various systems in ROM for handling interrupts. Once you understand how the 6502 handles interrupts it would then be well to see how this is implemented on your own particular machine.
 
Chapter 7 discusses interfacing hardware mainly the 6520 family of programmable input output chips. These chips are the mainstay of most simple 1/0 boards. The author refers the reader to the documentation supplied by the manufacturer of these chips for the details of their use. In my experience this will give the reader a valuable exercise in understanding technical jargon which can be at least for a while a most frustrating experience.
 
The remainder of the book is comprised of valuable chapters on application examples, data structures and program development which allow the reader to put into practice the principles he has presl.unably learned in the preceding chapters. These chapters are not only valuable to the 6502 programmer but of value to anyone interested in these topics.
 
One important development in 6502 technology which has occurred since the publication of this book is the introduction of the CMOS (complementary metal-oxide semiconductor) version of the '6502. This chip is pin and software compatible with the earlier versions with the added advantages of lower power consumption and an extended instruction set. Additionally this chip has been changed to iron out some of the minor anomalies which are poorly docmnented in most of the literature including Programming the 6502. I would suggest that anyone with a serious interest in 6502 programming read and keep an article in. BYTE magazine called "The CMOS 6502" by Steven Hendrix (December, 1983) for a complete discussion of the CMOS 6502 as well as the various anomalies of the older version.
 
On the whole I found Programming the 6502 an excellent learning tool for 6502 machine language programming. A student armed with a good assembler and this book as well as a 6502 can quickly master most of the techniques necessary for successful program writing. As I pointed out in an earlier review in this newsletter, however, the art of programming is best learned by actually sitting down and writing a program. Mr. Zaks has made this chore easier.
 
•Assistant Professor of Chemistry
University of Alabama in Birmingham, University Station
Birmingham, Alabama 35294

 

Date: 
03/10/95 to 03/14/95