Programming the 6502 - Zaks

From C64-Wiki
Jump to navigationJump to search
Programming the 6502 - Zaks
Title Cover
Language English
Author(s) Rodnay Zaks
Publisher SYBEX
Year 1978, 1983
ISBN ISBN 0-89588-135-7
Original price ? U$/DM/€
Media {{{Media}}}
Pages 412, 386
Last Edition Fourth Edition (April 1983)
Genre Programming, Hardware
Information The 6502 book series:
- Vol.1: Programming the 6502
- Vol.2: 6502 Applications Book
- Vol.3: Advanced 6502 Programming
- Vol.4: 6502 Games

Description & Table of Contents[edit]

This book is a great reference for those interested in Assembly/Machine language programming on computers using the MOS Technology 6502 based microprocessor. Zaks gives a detailed description of how the processor works along with a description of the instruction set used by the 6502. Here's a list of chapter headings:


I.   Basic Concepts..............................7
 Introduction. What is Programming? Flowcharting.
Information. Representation.
II. Hardware Organization......................38 Introduction. System Architecture. International
Organization of the 6502 The Instruction Execution Cycle.
The Stack. The Paging Concept. The 6502 Chip.
Hardware Summary.
III. Basic Programming Techniques...............53 Introduction. Arithmetic Programs. BCD Arithmetic.
Important Self-Test. Logical Operations. Subroutines.
IV. The 6502 Instruction Set...................99 PART 1-OVERALL DESCRIPTION Introduction. Classes of Instructions.
Instructions Available on the 6502.
PART 2-THEIR INSTRUCTIONS Abbreviations. Description of Each Instruction. V. Addressing Techniques.....................188 Introduction. Addressing Modes. 6502 Adressing
Modes. Using the 6502 Adressing Modes. Summary.
VI. Input/Output Techniques...........211 Introduction. Input/Output. Parallel World transfer.
Bit Serial Transfer. Basic I/O Summary. Communicating with
Input/Output Devices. Peripherals Summary. Input/Output Scheduling.
Summary. Exercises.
VII. Input/Output Devices......................254 Introduction. The Standard PIO (6520). The Internal
Control register. The 6530. Programming a PIO. The 6522.
The 6532. Summary.
VII. Application Examples......................262 Introduction. Clear a Section of Memory.
Polling I/O Devices. Getting Characters In. Testing a Character.
Bracket testing. Parity Generation.
Code Conversion: ASCII to BCD. Find the Largest Element of
a Table Sum of N Elements. A Cheksum Computation. Count the Zeroes.
A String Search. Summary.
IX. Data Structures...........................275 PART 1-DESIGN CONCEPTS Introduction. Pointers. Lists. Searching and
Sorting. Summary. Data Structures.
PART 2-DESIGN EXAMPLES Introduction. Data Representation for the List.
A Simple List. Alphabetic List. Binary Tree. A Hashing Algorithm.
Bubble-Sort. A Merge Alogrithm. Summary
X. Program Development.......................343 Introduction. Basic Programming Choices. Software
Support. The Program Development Sequence. The Hardware Alternatives.
Summary of Hardware Alternatvives. Summary of Hardware Resources.
The Assembler. Macros. Conditional Assembly. Summary
XI. Conclusion................................368 Technological Development. The Next Step APPENDICES:....................................371 A. Hexadecimal Conversion Table B. 6502 Instruction-set: Alphabetic C. 6502 Instruction-set: Binary D. 6502 Instruction-set: Hexadecimal and Timing E. ASCII Table F. Relative Branch Table G. Hex Opcode Listing H. Decimal to BCD Conversion I. Answers to the Exercises INDEX...........................................402


  • Page vii:

This book has been designed as a complete self-contained text to learn programming, using the 6502. It can be used by a person who has never programmed before, and should also be of value to anyone using the 6502.

For the person who has already programmed, this book will teach specific programming techniques using (or working around) the specific characteristic of the 6502. This text covers the elementary to intermediate techniques required to start programming effectively.
This book is based on the author's experience in teaching more than 1000 persons how to program microcomputers. As a result, it is strongly structured. Chapters normally go from the simple to the complex. For readers who have already learned elementary programming, the introductory chapter may be skipped. For others who have never programmed, the finial sections of some chapters may require a second reading. The book has been designed to take the reader systematically through all the basic concepts and techniques required to build increasingly complex programs. It is, therefore, strongly suggested that the ordering of the chapters be followed. In addition, for effective results, it is important that the reader attempt to solve as many exercises as possible. The difficulty within the exercises has been carefully graduated.They are designed to verify that the material which has been presented is really understood. Without doing the programming exercises, it will not be possible to realize the fill value of this book as an educational medium. Several of the exercises may require time, such as the multiplication exercise for example. However, by doing these, you will actually program and learn by doing. This is indispensable. ...

Preface to the fourth Edition[edit]

  • Page viii:

In the five years since this book was originally published, the audience of 6502 microprocessor user has grown exponentially, and it continues to grow. This book has expanded with its audience.

The Second Edition increased in size by alomost 100 pages, with most of new material being added to Chapters 1 and 9. Additional improvements have been made continually throughout the book. In this Fourth Edition, answers to the exercises have been included as an appendix (Appendix I). These answers appear in response to the request of many readers, who wanted to make sure their knowledge of 6502 programming was thorough.

I would like to thank the many readers of the previous editions who have contributed value suggestions for improvement. Special acknowledgements are due to Eric Novikoff and Chris Williams for their contributions examples in Chapter 9. Special thanks also go to Daniel J. David, for his many suggested improvements. A number of changes and enhancements are also due to the valueable analysis and comments proposed by Philip K. Hooper, John Smith, Ronald Long, Charles Curlay, N. Harris, John McClenon, Douglas Trusty, Fletcher Carson, and Professpr Myron Calhoun.


  • Page 191/192:

Indexed Addressing

Indexed addressing is a technique specifically useful to access successively the elements of a block or of a table. This will be illustrated by examples later in this chapter. The principle of indexed addressing is that the instruction specifies both an index register and an address. In the most generals scheme, the contents of the register are added to the address to provide the finals address- In this way, the address could be the beginning of a table in the memory. The index register would then be used to access successively all the elements of the table in an efficient way. In practice, restrictions often exist and may limit the size of the index register, or the size of the address or displacement field.


  • Page 206, section "ADRESSING TECHNIQUES", "A Block Transfer Routine (more than 256 elements)", 4th edition[1])
    • The given routine is buggy:
      • The label "DONE" is missing.
      • If the length is not a multiple of 256 (a page) the first byte of the remaining partial block won't be copied and one byte past the range is transferred too.
      • If the length is less than 256 (block count is 0) the first whole block will be copied anyway.
      • The routine is limited to 32 Kbyte (what isn't mentioned in the explaining text at all).
      • In case of overlapping source and destination ranges it would be possible to move to lower addresses, but the copy loop uses decrementation which limits the usability in that way that the distance has to be at least 256 bytes.
    • In the explanation text:
      • Paragraph 3, line 9: "We will now use indexed indirect addressing."
        It should read "... indirect indexed addressing."


JohannKlasek: "This book was a great introduction into the 6502 world and very helpful for me. It covers all the things which one has to know. However, this book should be used with caution. Typographic errors and flaws in some sample programs might exist.
I wonder if there weren't some newer editions planed covering newer 6502 family developments (in comparison to the german translation which has 10 editions so far)."



  1. Video at YouTube : 8-Bit Show and Tell: Fixing a Bug in Rodnay Zaks' "Programming the 6502"