# Programming the 6502, Fourth Edition — source transcripts, page 1

[Canonical transcript page](https://www.vintageapple.net/transcripts/media/va-programming-the-6502-1983-11dfd6/1)

## Transcribed source material

Machine transcriptions and image descriptions; uncertain copy may be marked [illegible]. Verify against the linked originals. Historical rights remain with the original owners.

These are transcribed excerpts, not the full publications. Open the originals for remaining pages.

### Image 1

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-programming-the-6502-1983-11dfd6/1#scan-1f5afe29231b375ee263b414667d694e463d9cac8e345a42736f14618406ac94)

Programming the 6502

Transcribed text:

Programming the
6502
Rodnay Zaks
SYBEX

Image description: A book cover with a gradient blue background showing a large colorful 3D rendering of a microchip with gold pins, containing red, green, and blue geometric shapes, with the title at top and author name and SYBEX logo at bottom.

Reading notes: Title line 'Programming the' is in lighter blue text and the number '6502' is in large white type; the layout is read top to bottom.

Printed product names: 6502

Languages: English

[Original Image 1](https://www.vintageapple.net/files/23ad7cd8e0c72ab2f08338bbdd188d60c89dc37ce0a7e257ed6d43e1b593f004/13371812b1316395bf6cf69c.webp)

### PDF page 1

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-programming-the-6502-1983-11dfd6/1#scan-23b8eeb9be16991fe9b6efa8d9b7b75e1a8b63ff5dd7f4c92ec5bc639ec566a4)

Programming the 6502

Transcribed text:

Programming the
6502
Rodnay Zaks
SYBEX

Image description: A book cover showing a glossy, exploded-style rendering of a 6502 microprocessor chip in red, green, and blue translucent blocks with gold pins, against a dark-to-light blue gradient background, with a SYBEX logo at lower right.

Reading notes: Title text 'Programming the' is in lighter blue smaller type above the large '6502'; reading order follows that layout. SYBEX logo text is stylized and read as 'SYBEX'.

Printed product names: 6502

Languages: English

[Original PDF page 1](https://www.vintageapple.net/files/678472b7a8b848339d7ce1fc80c79eacc8e051adec0280028c0439f80d14be5f/Programming_the_6502_1983.pdf#page=1)

### PDF page 2

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-programming-the-6502-1983-11dfd6/1#scan-2537054115d251376d224b98865e108945311721749d0256619fd425f8265789)

Image description: The image is a plain, entirely white page with no visible artwork, layout elements, or text.

[Original PDF page 2](https://www.vintageapple.net/files/678472b7a8b848339d7ce1fc80c79eacc8e051adec0280028c0439f80d14be5f/Programming_the_6502_1983.pdf#page=2)

### PDF page 3

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-programming-the-6502-1983-11dfd6/1#scan-c2ab1cd047359fee0e493a3db894943785735418cce509e612871afb1f7ba154)

Image description: The image is a plain, blank white page with no visible artwork, layout, or text.

[Original PDF page 3](https://www.vintageapple.net/files/678472b7a8b848339d7ce1fc80c79eacc8e051adec0280028c0439f80d14be5f/Programming_the_6502_1983.pdf#page=3)

### PDF page 4

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-programming-the-6502-1983-11dfd6/1#scan-e239782dda8f08461b02a277084d9c2c7953d8a6f556d2c5468950f3a48130fd)

Transcribed text:

Cover art: Daniel Le Noury
Every effort has been made to supply complete and accurate information. However,
Sybex   assumes no responsibility for its use, nor for any infringements of patents or other
rights of third parties which would result. No license is granted by the equipment manufac-
turers under any patent or patent right. Manufacturers reserve the right to change circuitry
at any time without notice.
Copyright   ©   1983   SYBEX   Inc. 2344   Sixth   Street,   Berkeley, CA   94710.   World rights
reserved. No part of this publication may be stored in a retrieval system, copied, transmit-
ted, or reproduced in any way, including, but not limited to photocopy, photography, mag-
netic or other recording, without the prior agreement and written permission of the
publisher.
ISBN   0-89588-135-7
Library of Congress Card Number: 83-61686
First Edition published 1978. Fourth Edition 1983
Printed in the   United   States   of America
10   9 8 7 6   5   4 3 2   I

Printed dates: 1983 · 1978

Languages: English

[Original PDF page 4](https://www.vintageapple.net/files/678472b7a8b848339d7ce1fc80c79eacc8e051adec0280028c0439f80d14be5f/Programming_the_6502_1983.pdf#page=4)

### PDF page 5

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-programming-the-6502-1983-11dfd6/1#scan-524f608b3ce79de7f94e0d72f7d21b9b47d80da0d9abdd3d49b541dd45d568fa)

Transcribed text:

CONTENTS
PREFACE   . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .   vii
I.   BASIC   CONCEPTS   ................................   7
Introduction.   What   is   Programming?   Flowcharting.   Information
Representation.
II.   6502   HARDWARE   ORGANIZATION   ...............   38
Introduction. System Architecture. lnlernal 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. Summary.
IV.   THE   6502   INSTRUCTION   SET   .....................   99
PART   I-OVERALL   DESCRIPTION
Introduction. Classes of Instructions. Instructions Available on the   6502.
PART2-THE   INSTRUCTIONS
Abbreviations. Description of   Each Instruction.
V.   ADDRESSING   TECHNIQUES   ....................   188
Introduction. Addressing Modes.   6502   Addressing Modes. Using the   6502
Addressing Modes. Summary.
VI.   INPUT/OUTPUT   TECHNIQUES   .................. 211
Introduction. Input/Output. Parallel Word Transfer. Bit Serial Transfer.
Basic   110   Summary.   Communicating   with   Input/Output   Devices.
Peripheral   Summary.   Input/Output   Scheduling.   Summary.   Exercises.
v

Reading notes: Some words in the table of contents show OCR-style spacing or character damage, such as 'lnlernal' and 'Summary' splits.

Printed product names: 6502

Languages: English

[Original PDF page 5](https://www.vintageapple.net/files/678472b7a8b848339d7ce1fc80c79eacc8e051adec0280028c0439f80d14be5f/Programming_the_6502_1983.pdf#page=5)

### PDF page 6

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-programming-the-6502-1983-11dfd6/1#scan-2ad07545a15a9eac5ee6929161ca04719856441336aa4bdb9885aaa12b20cc0f)

VII. INPUT/OUTPUT DEVICES

Transcribed text:

VII.   INPUT   /OUTPUT   DEVICES ...................... 254
VIII.
Introduction.   The Standard   PIO   (6520).   The Internal   Control   Register.
The   6530.   Programming a   PIO.   The 6522. The 6532. Summary.
APPLICATION EXAMPLES ..................... 262
Introduction.   Clear   a Section of Memory. Polling I   10   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 Checksum Computation.   Count   the Zeroes. A
String   Search.   Summary.
IX.   DATA   STRUCTURES   ............................ 275
PART I-DESIGN   CONCEPTS
Introduction. Pointers. Lists. Searching and Sorting. Summary. Data Structures.
PART 2-DES/GN EXAMPLES
Introduction. Data Representation for the List. A   Simple   List. Alphabetic
List. Binary Tree. A Hashing Algorithm. Bubble-Sort. A Merge Algorithm.
Summary.
X.   PROGRAM DEVELOPMENT ....................   343
Introduction. Basic Programming   Choices.   Software Support.   The Pro-
gram Development Sequence.   The Hardware Alternatives.   Summary   of
Hardware Alternatives.   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
vi

Reading notes: Table of contents format; page numbers and section headings may not reflect a continuous reading order. Some characters in the OCR text are unclear, such as '/' and ',' within headings.

Languages: English

[Original PDF page 6](https://www.vintageapple.net/files/678472b7a8b848339d7ce1fc80c79eacc8e051adec0280028c0439f80d14be5f/Programming_the_6502_1983.pdf#page=6)

### PDF page 7

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-programming-the-6502-1983-11dfd6/1#scan-6a739cee55badd9245b2f6f779cd151e5d42add3e4dbe0481278125c386f29bb)

Transcribed text:

PREFACE
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 characteristics of the   6502.   This text covers the
elementary to intermediate techniques required to start pro-
gramming effectively.
This text aims at providing a true level of competence to the
person   who   wishes   to   program   using   this   microprocessor.   Nat-
urally, no book will teach effectively how to program, unless one
actually practices. However, it is hoped that this book will take
the reader to the point where he feels that he can start program-
ming by himself and solve simple or even moderately complex
problems using a microcomputer.
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 final sections of some
chapters may require a second reading.   The book has been   de-
signed   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 pro-
gramming exercises, it will not be possible to realize the full
value of this book as an educational medium.   Several   of the exer-
cises may require time, such as the multiplication exercise for
example. However, by doing these, you   ~ill   actually program and
learn   by   doing.   This is indispensable.
For those who will have acquired a taste for programming when
reaching   the.end   of this volume,   companion volumes are available:
vii

Reading notes: Source text is a preface page with a page marker 'vii'; no primary heading is printed. Line-break hyphenation in the extracted copy (e.g., 'pro-gramming', 'pro-gram') may affect exact word forms.

Printed product names: 6502

Languages: English

[Original PDF page 7](https://www.vintageapple.net/files/678472b7a8b848339d7ce1fc80c79eacc8e051adec0280028c0439f80d14be5f/Programming_the_6502_1983.pdf#page=7)

### PDF page 8

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-programming-the-6502-1983-11dfd6/1#scan-0cffeaba584b4409c6cd5cb096e3c6b04f53ddcb369afa3eb86e3c629b67c878)

Transcribed text:

-''6502   Applications'' covers input/output.
-''Advanced   6502   Programming'' covers complex algorithms.
Other   books in this series cover programming for other popular
microprocessors.
For those who wish to develop their hardware knowledge, it is
suggested that the reference books   "From   Chips to   Systems"   (ref.
C201A)   and   "Microprocessor   Interfacing   Techniques"   (ref.   C207)   be
consulted.
The author would like to thank Rockwell International, who   pro-
vided access to one of the first   ASM65   development systems.
The contents of this book have been checked carefully and are
believed to be reliable. However, inevitably, some typographical
or other errors will be found. The author will be grateful for any
comments by alert readers so that future editions may benefit from
their experience. Any other suggestions for improvements, such as
other programs desired, developed, or found of value by readers,
will be appreciated.
PREFACETOTHEFOURTHEDITION
In the five years since this book was originally published, the audience
of   6502   microprocessor users has grown exponentially, and it continues
to grow. This book has expanded with its audience.
The   Second   Edition increased in size by almost I   00   pages, with most
of the new material being added to Chapters I and 9. Additional
improvements have been made continually throughout the book. In this
Fourth Edition, answers to the exercises have been included as an appen-
dix (Appendix I). These answers appear in response to the request of
many readers, who wanted to make sure that their knowledge of   6502
programming was thorough.
I would like to thank the many readers of the previous editions who
have contributed valuable suggestions for improvement.   Special
acknowledgements are due to Eric Novikoff and Chris Williams for their
contributions to the answers to the exercises, as well as to the complex
programming examples in Chapter 9.   Speeial   thanks also go to Daniel J.
David, for his many suggested improvements. A number of changes and
enhancements are also due to the valuable analysis and comments pro-
posed by Philip K. Hooper, John   Smith,   Ronald Long, Charles Curlay,
N. Harris, John McClenon, Douglas Trusty, Fletcher Carson, and Pro-
fessor Myron Calhoun.
viii

Reading notes: Possible OCR spacing and character errors in several words (e.g., 'I 00 pages', 'Speeial') Reading order of front matter fragments is uncertain

Printed product names: 6502 Applications · Advanced 6502 Programming · ASM65 · From Chips to Systems · Microprocessor Interfacing Techniques

Languages: English

[Original PDF page 8](https://www.vintageapple.net/files/678472b7a8b848339d7ce1fc80c79eacc8e051adec0280028c0439f80d14be5f/Programming_the_6502_1983.pdf#page=8)

### PDF page 9

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-programming-the-6502-1983-11dfd6/1#scan-b1ad03838c40fc1567be33fc23c1d166a2940690ee3372c9996db9c541355359)

Transcribed text:

Acknowledgements
The author would like to express his appreciation to Rockwell Interna-
tional and, in particular, to Scotty Maxwell, who made available to him
one of the very first system 65 development systems. The availability of
this powerful development tool, at the time the first version of this book
was being written, was a major help for the accurate and efficient check-
out of all the programs. I would also like to thank Professor Myron
Calhoun for his contributions.

Printed product names: system 65

Languages: English

[Original PDF page 9](https://www.vintageapple.net/files/678472b7a8b848339d7ce1fc80c79eacc8e051adec0280028c0439f80d14be5f/Programming_the_6502_1983.pdf#page=9)

### PDF page 10

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-programming-the-6502-1983-11dfd6/1#scan-170461f44cbfcb62575637eef8acfe628a9a09f0244aa8d8297ca8bb7946f9fc)

BASIC CONCEPTS

Transcribed text:

1
BASIC   CONCEPTS
INTRODUCTION
This chapter will introduce the basic concepts and definitions   re-
lating to computer programming. The reader already familiar with
these concepts may want to glance quickly at the contents of this
chapter and then move on to Chapter 2.   It   is suggested, however,
that even the experienced reader look at the contents of this   intro-
ductory chapter. Many significant concepts are presented here   in-
cluding, for example, two's complement, BCD, and other   represen-
tations.   Some   of these concepts may be new to the reader; others
may improve the knowledge and skills of experienced programmers.
WHAT   IS   PROGRAMMING?
Given a problem, one must first devise a solution. This solution,
expressed as a step-by-step procedure, is called an   algorithm.   An
algorithm is a step-by-step specification of the solution to a given
problem. It must terminate in a finite number of steps. This
algorithm may be expressed in any language or symbolism. A   sim-
ple example of an algorithm is:
I-insert key in the keyhole
2-turn key one full turn to the left
3-seize doorknob
4-turn doorknob left and push the door
7

Languages: English

[Original PDF page 10](https://www.vintageapple.net/files/678472b7a8b848339d7ce1fc80c79eacc8e051adec0280028c0439f80d14be5f/Programming_the_6502_1983.pdf#page=10)

### PDF page 11

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-programming-the-6502-1983-11dfd6/1#scan-f51058497d9df84169adaffd73c4cec45f2488e6972d250fffd897479c72ea2a)

Transcribed text:

PROGRAMMING   THE   6502
At this point, if the algorithm is correct for the type of lock   in·
volved, the door will open. This four-step procedure qualifies as an
algorithm for door opening.
Once   a solution to a problem has been expressed in the form of
an algorithm, the algorithm must be executed by the computer.
Unfortunately, it is now a well-established fact that computers
cannot   understand   or   execute   ordinary   spoken   English   (or   any
other human language). The reason lies in the   syntactic ambiguity
of all common human languages.   Only   a well-defined subset of
natural language can be   "understood"   by the computer. This is
called a   programming language.
Converting an algorithm into a sequence of instructions in a   pro-
gramming language is called   programming.   To be more specific,
the actual translation phase of the algorithm into the program-
ming language is called   coding.   Programming really refers not just
to the coding but also to the overall design of the programs and
"data   structures"   which will implement the algorithm.
Effective programming requires not only understanding the
possible implementation techniques for standard algorithms, but
also the skillful use of all the computer hardware resources, such as
internal registers, memory, and peripheral devices, plus a creative
use of appropriate data   structures.   These   techniques   will   be
covered in the next chapters.
Programming also requires a strict   documentation   discipline, so
that the programs are understandable to others, as well as to the
author. Documentation must be both internal and external to the
program.
Internal program documentation refers to the comments placed
in the body of a program, which explain its operation.
External documentation refers to the design documents which
are separate from the program: written explanations, manuals,
and flowcharts.
FLOWCHARTING
One   intermediate   step is   almost always   used   between   the
algorithm   and the   program.   It is called a   fl,owchart.   A flowchart is
simply a symbolic representation of the algorithm expressed as a
sequence of rectangles and diamonds containing the steps of the
algorithm.   Rectangles are used for   commands,   or   "executable
statements."   Diamonds are used for   tests   such as:   If   information
8

Reading notes: Running headline "PROGRAMMING THE 6502" is spaced out and may be an OCR artifact; the heading is not a primary headline. "fl,owchart" appears to be an OCR error for "flowchart".

Languages: English

[Original PDF page 11](https://www.vintageapple.net/files/678472b7a8b848339d7ce1fc80c79eacc8e051adec0280028c0439f80d14be5f/Programming_the_6502_1983.pdf#page=11)

[Next transcribed scans](https://www.vintageapple.net/transcripts/media/va-programming-the-6502-1983-11dfd6/2.md)
