6502 assembly language programming
Leventhal, Lance A., 1945
This book was produced in EPUB format by the Internet Archive.
The book pages were scanned and converted to EPUB format automatically. This process relies on optical character recognition, and is somewhat susceptible to errors. The book may not offer the correct reading sequence, and there may be weird characters, non-words, and incorrect guesses at structure. Some page numbers and headers or footers may remain from the scanned page. The process which identifies images might have found stray marks on the page which are not actually images from the book. The hidden page numbering which may be available to your ereader corresponds to the numbered pages in the print edition, but is not an exact match; page numbers will increment at the same rate as the corresponding print edition, but we may have started numbering before the print book's visible page numbers. The Internet Archive is working to improve the scanning process and resulting books, but in the meantime, we hope that this book will be useful to you.
The Internet Archive was founded in 1996 to build an Internet library and to promote universal access to all knowledge. The Archive's purposes include offering permanent access for researchers, historians, scholars, people with disabilities, and the general public to historical collections that exist in digital format. The Internet Archive includes texts, audio, moving images, and software as well as archived web pages, and provides specialized services for information access for the blind and other persons with disabilities.
Created with abbyy2epub (v.1.7.0)
DAVID L BURKE1129 N Bitting StWichita KS 67203
6502
RSSCmBLV IflflGURGCPROGRnmmmG
Asscmoiv larguagcPROGRnmminG
Lance R. leventhal
OSBORN E/McGraw-HillBerkeley, California
Published byOSBORNE/McGraw-Hill630 Bancroft WayBerkeley, California 94710U.S.A.
For information on translations and book distributors outside ofthe U.S.A., please write OSBORNE/McGraw-Hill at the aboveaddress.
6502 ASSEMBLY LANGUAGE PROGRAMMING
Copyright 1979 by McGraw-Hill, Inc. All rights reserved. Printed in theUnited States of America. No part of this publication may be reproduced,stored in a retrieval system, or transmitted in any form or by any means,electronic, mechanical, photocopying, recording or otherwise without theprior written permission of the publishers, with the exception that the program listings may be entered, stored, and executed in a computer system, butthey may not be reproduced for publication.
6 7 8 9 0 DODO 8 7 6 5 4 3ISBN 0-931988-27-6Cover design by K.L.T. van Genderen.
ACKNOWLEDGMENTS
The author would like to acknowledge the following people: Mr. Curt Ingraham and Ms. Janice Enger of OSBORNE/McGraw-Hill, who made manycorrections, improvements, and suggestions; Mr. Gary Hankins, Mr. MichaelLehman, Mr. Winthrop Saville, and Mr. Stanley St. John of Sorrento ValleyAssociates, who provided assistance and examples; Mr. Leo Scanlon ofRockwell International, who provided constant encouragement and referencematerials; Mr. Charles Peddle of Commodore International, who providedsome reference material; Ms. Marielle Carter of Sorrento Valley Associates,who typed some of the material; Mr. Stanley Rogers of the Society for Computer Simulation, who has continually encouraged clear and concise technical writing; and his wife Donna, for her patience and understandingthroughout the writing of this book.
Others who provided assistance and suggestions were Mr. Colin Walsh, Mr.Romeo Favreau, Mr. Richard Deisher, Mr. Karl Amatneek, Mr. Robert Stow,and Mr. Irv Stafford. Other students and colleagues also helped to keep theauthor on the right track.
The author, of course, bears responsibility for any remaining errors, misconceptions, and misinterpretations.
A special note of acknowledgment should go to the magazine MICRO, whichis entirely dedicated to 6502-based personal computers. Besides numerousarticles, MICRO also contains resource and reference lists related to the6502. MICRO is published monthly by Dr. Robert Tripp, The ComputeristInc., P.0, Box 3, South Chelmsford, MA 01824.
This book is dedicated on behalf of Amanda Catherine (Elizabeth Bramble) tosome very special people Catherine Greenlee, Max and Peggy Leventhal,Al and Rose Rosen, and Julius and Jeanette Ross.
The author would like to thank Karl Amatneek, Mel Evans, and particularlyPhilip Hooper for their lists of corrections to earlier printings of this book.
Contents
Chapter Page
1 Introduction to Assembly Language Programming 1-1
How This Book Has Been Printed 1-1
The Meaning of Instructions 1-1
A Computer Program 1-2
The Programming Problem 1-2
Using Octal or Hexadecimal 1-3
Instruction Code Mnemonics 1-4
The Assembler Program 1-5
Additional Features of Assemblers 1-6
Disadvantages of Assembly Language 1-6
High-Level Languages 1-7
Advantages of High-Level Languages 1-7
Disadvantages of High-Level Languages 1-8
High-Level Languages for Microprocessors 1-9
Which Level Should You Use? 1-10
How About the Future? 1-11
Why This Book? 1-12
References 1-13
2 Assemblers 2-1
Features of Assemblers 2-1
Assembler Instructions 2-1
Labels 2-2
Assembler Operation Codes (Mnemonics) 2-4
Pseudo-Operations 2-4
The Data Pseudo-Operation 2-5
The Equate (or Define) Pseudo-Operation 2-6
The Origin Pseudo-Operation 2-7
The Reserve Pseudo-Operation 2-7
Linking Pseudo-Operations 2-8
Housekeeping Pseudo-Operations 2-9
Labels with Pseudo-Operations 2-9
Addresses and the Operation Field 2-10
Conditional Assembly 2-12
Macros 2-13
Comments 2-15
Types of Assemblers 2-16
Errors 2-17
Loaders 2-17
References 2-18
Contents (Continued)
Chapter Page
3 The 6502 Assembly Language Instruction Set 3-1
CPU Registers and Status Flags 3-3
6502 Memory Addressing Modes 3-5
Memory Immediate 3-6
Memory Direct 3-7
Implied or Inherent Addressing 3-8
Accumulator Addressing 3-8
Pre-lndexed Indirect Addressing 3-9
Post-Indexed Indirect Addressing 3-10
Indexed Addressing 3-11
Indirect Addressing 3-13
Relative Addressing 3-14
6502 Instruction Set 3-15
Abbreviations 3-15
Instruction Mnemonics 3-17
Instruction Object Codes 3-17
Instruction Execution Times 3-17
Status 3-17
ADC Add Memory, with Carry, to Accumulator 3-38
AND AND Memory with Accumulator 3-40
ASL Shift Accumulator or Memory Byte Left 3-41
BCC Branch if Carry Clear (C = 0) 3-43
BCS Branch if Carry Set (C =1) 3-44
BEQ Branch if Equal to Zero (Z = 1) 3-44
BIT Bit Test 3-45
BMI Branch if Minus (S = 1) 3-47
BNE Branch if Not Equal to Zero (Z = 0) 3-47
BPL Branch if Plus (S = 0) 3-48
BRK Force Break (Trap or Software Interrupt) 3-49
BVC Branch if Overflow Clear (V = 0) 3-51
Next page