6502 ASSEMBLY LANGUAGE SUBROUTINES PDF

Assembly Language Subroutines Lance A. Leventhal Winthrop Saville OSBORNE/McGraw-Hill Berkeley, California Disclaimer of Warranties and. Assembly Language Subroutines. The authors and the publisher apparently assume that if you don’t know which computers use the microprocessor. assembly language subroutines / Lance A. Leventhal, Winthrop Saville. Subjects: Assembly languages (Electronic computers) · (Microprocessor) > .

Author: Mazull Gardakasa
Country: Algeria
Language: English (Spanish)
Genre: Automotive
Published (Last): 7 October 2012
Pages: 443
PDF File Size: 14.45 Mb
ePub File Size: 10.23 Mb
ISBN: 864-3-64128-602-8
Downloads: 72200
Price: Free* [*Free Regsitration Required]
Uploader: Gardazragore

Search the history of over billion web pages on the Internet. The authors and the publishers make no expressed or implied warranty of any kind with regard to these programs nor the sup- plementary documentation in this book. In no event shall the authors or the publishers be liable for incidental or consequential damages in con- nection with or arising out of the furnishing, performance, or use of any of these programs.

Berkeley, Aszembly U. For information on translations and book distributors outside of the U. Printed aseembly the United States of America. Except as permitted under the Copyright Act ofno part of this publication may be reproduced or distributed in any form or by any means, or stored in a data base or retrieval system, without the prior written permission of the publisher, with the exception that the program listings may be entered, stored, and executed in a computer system, but they may not be reproduced for publication.

Text design by Paul Butzler. It contains an overview of assembly language program- ming for a particular microprocessor and a collection of useful routines.

In writing the routines, we have used a standard format, documentation package, and parameter passing techniques. We have followed the rules of the original manufacturer’s assembler and have described the purpose, procedure, param- eters, results, execution time, and memory usage of each routine.

This overview of assembly language programming provides a summary for those who do not have the time or need for a complete textbook such as is pro- vided already in the Assembly Language Programming series. Chapter 1 contains an introduction to assembly language programming for the particular processor and a brief summary of the major features that differentiate this processor from other microprocessors and minicomputers.

Chapter 2 describes how to imple- ment instructions and addressing modes that are not explicitly available. Chapter 3 discusses common errors that the programmer is likely to encounter. The collection of routines emphasizes common tasks that occur in many applications such as code conversion, array manipulation, arithmetic, bit manipulation, shifting functions, string manipulation, summation, sorting, and searching.

You should be able to use these routines as subroutines in actual applications and as guidelines for more complex pro- grams. We have aimed this book at the person who wants to use assembly language immediately, rather than just learn about it.

This book can also serve as supplementary material for students of the Assem- bly Language Programming series. Subrojtines book should save the reader time and effort.

There is no need to write, debug, test, or optimize standard routines, nor should the reader have to search through material with which he or she is thoroughly familiar. We have organized and indexed this book for rapid use and reference.

Obviously, a book with such an aim demands response from its readers. We have, of course, tested all the programs thoroughly and documented them carefully. If you find any errors, please inform the publisher. If you have sugges- tions for additional topics, routines, programming hints, index entries, and so forth, please tell us about them.

We have drawn on our programming experience to develop this book, but we need your help to improve it. We would greatly appreciate your comments, criticisms, and suggestions. The stack pointer always contains the address of the next available stack location on page 1 of memory addresses l6 through 01FF, 6. The P status or F flag register consists of a set of bits with independent functions and meanings, organized as shown in the following diagram: Pairs of memory locations on page may also be used as word-length registers to hold indirect addresses.

  EL AMOR ES UNA DECISION GARY SMALLEY PDF

The lower address holds the less significant byte and the higher address holds the more significant byte. Since the pro- vides automatic wraparound, addresses 00FF l6 and ]6 form a rarely used pair. BLOCK Adsembly bytes of memory; reserve the specified number of bytes of memory for temporary storage. BYTE Form byte-length data; place the specified 8-bit data in the next available memory locations.

DBYTE Form double-byte word subrourines data with more significant byte subriutines place the specified bit data in the next available memory locations with more significant byte first.

END End of program. EQU Equate; define the attached label. It presents techniques for per- forming the following operations: Suvroutines chapter provides a brief guide to assembly language pro- gramming for those who have an immediate application in mind. Being aware of these unusual features can save you a great deal of time and trouble. The Carry flag acts as an inverted borrow in subtraction. The SBC instruction accounts for this inversion by subtracting 1 -Carry from the usual difference.

Thus, the Carry has the opposite meaning after subtraction or comparison on the than it has on most other computers. If you wish to exclude the Carry flag, you must clear it before addition or set it before subtraction.

There are no bit registers and no operations that act on bit quantities. The lack of bit registers is commonly overcome by using pointers stored on page and the indirect indexed postindexed addressing mode. However, both initializing and changing those pointers require sequences of 8-bit operations. For many other instructions, however, you can simulate indirect addressing by clearing index register Y and using indirect indexed addressing, or by clearing index register X and using indexed indirect addressing.

Both of these modes are limited to indirect addresses stored on page 0. The stack pointer subroutlnes the less significant byte of the next empty address.

Thus, the stack is limited to bytes of memory. RTS Return from Subroutine loads the program counter from the top of the stack and then adds 1 to it. You must remember this offset of 1 in debugging and using JSR or RTS for purposes other than ordinary calls and returns. The Decimal Mode D flag is used to perform decimal arithmetic. When this flag is set, all additions and subtractions produce decimal results. Increments and decrements, however, produce binary results regardless of the mode.

The problem with this approach is that you may not be sure of the initial or current state of the D flag the processor does not initialize it on Reset. A simple way to avoid problems in programs that use Addition or Subtraction instructions is to save the original D flag in the stack, assign D the appropriate value, and restore the original value before exiting. Interrupt service routines, in particular, should always either set or clear D before executing any addition or subtraction instruc- tions.

The overall system startup routine must initialize D usually to 0, indicating bin- ary mode, with CLD.

Most based operating systems assume the binary mode as a default and always return to that mode as soon as possible. A minor quirk of the ‘s decimal mode is that the Zero and Negative flags are no longer universally 5602. These flags reflect only the binary result, not the decimal result; only the Carry flag always reflects the decimal result.

Thus, for example, subtracting 80 l6 from 50 16 in the decimal mode sets the Negative flag languagd the binary result is D0 16even though the decimal result 70 16 has a most significant bit of 0. Similarly, adding 50 16 and 50 16 in asswmbly decimal mode clears the Zero flag since the binary result is A0 I6even though the decimal result is zero.

Note that adding 50 16 and 50 16 in the decimal mode does set the Carry. Thus when working in the decimal mode, the programmer should use only branches that depend on the Carry flag or languxge that do not depend on the mode at all such as subtractions or comparisons followed by branches on the Zero flag.

  LEANORE ELLIOTT PDF

This is not the case with the, or Z microprocessors.

6502 assembly language subroutines

Storing data in memory does not affect assemvly flags! The index registers are only 8 bits long. This creates obvious problems in handling arrays or areas of memory that are longer than bytes.

To overcome this, use the indirect indexed postindexed addressing mode.

assembly language subroutines | Oxfam GB | Oxfam’s Online Shop

This mode allows you to store the starting address of the array in two memory locations on page 0. Whenever the program completes a byte section, it must add 1 to the more significant byte of the indirect address before langauge to the next section.

The processor knows that it has completed a section when index register Y returns to 0.

Note that we check lnguage Zero flag rather than the Carry flag since, as on most computers, Increment and Decrement instructions do not affect Carry. In the first place, it allows only direct addressing absolute 602 zero page. Thus, you can perform the following operations without loading the accumulator at all. The processor lacks some common instructions that are available on the, and similar processors.

Most of the missing instructions are easy to simulate, although the documentation can become awkward. There is also no direct way to load or store the stack pointer this can be done through index register Xload or store the status register this can be done through the stackor perform operations between registers one must be stored in memory.

Other missing instructions include Unconditional Relative Branch subroutinnes jump or assign a value to a flag and branch on it having that valueIncrement and Decrement Accumulator use the Addition and Subtraction instructionsArithmetic Shift copy bit 7 into Carry and rotateand Test zero or minus use a comparison with or an increment, decrement sequence. Weller 1 describes the definition of macros to replace the missing instructions. The uses the following common conventions: The order of the bytes is the same as in theZ, and microprocessors, but opposite the order used in and This convention is also used in thebut the obvious alternative last occupied location is used in the, Z, and microprocessors.

Instructions store data in the stack using postdecrementing they subtract 1 from the stack pointer after storing each byte and load data from the stack using preincrementing they add 1 to the stack pointer before loading each byte. Setting the flag with SEI disables the maskable interrupt and clearing the flag with CLI enables the maskable inter- rupt. This convention is the same as in the and xssembly the opposite of that used in the, and Z In particular, there are no address-length bit user registers.

Thus, variable addresses must normally be stored in pairs of memory locations on page and accessed indirectly using either preindexing indexed indirect addressing or postindexing indirect indexed addressing. The lack of bit registers also complicates the handling of arrays or blocks that occupy more than bytes of memory. Subrputines is the only register that normally has a zero page indexed mode except for the LDX STX instructionsand it is the only register that can be used for indexing with single-operand instructions such as shifts, increment, and decrement.

It is also the only register that can be used for preindexing, although that mode is not com- mon. Finally, it is the only register that can be used to load or store the stack pointer. Tables through contain lists of instructions having particular features. Table lists instructions that apply only to particular registers and Table lists instructions that can be applied directly to memory locations. Tables through list instructions that allow particular addressing modes: