27.11.22

6502 Tricks and traps by Joe Holt

Tips for surviving 6502 assembly-language programming

[Joe Holt is a freelance technical writer. He can be reached at 476 West Main Rd., El Centro, CA 92243. This is article from 1985.]

WITH THE ADVENT of complex microprocessors whose operation codes (op codes) begin to resemble some high-level languages, the days of the 6502 seem numbered. Indeed, a microprocessor with only three 8-bit registers and a 64 K-byte address space is apparently no match for a piece of silicon that can walk through 4 gigabytes of memory in 32-bit strides and work with hundreds of bits worth of registers. I won’t try to fool you: The 6502 will not be around forever. But when the last of its species emerges from the forge, it will be joining an installed base of more than 3 million 6502-based computers. There is merit, therefore, in discussing the peculiarities of this dying breed, the ins and outs of this most nonorthogonal microprocessor.

The 6502 has three 8-bit registers (only one of which can be used in arithmetic and Boolean operations), a single-page (256-byte) fixed stack, and an optimized performance when dealing with the first 256 bytes of memory. But what may be considered a tight architecture is befuddled by an instruction set full of inconsistency and seeming favoritism to certain combinations of addressing modes and op codes. Steve Wozniak even admitted that the only reason he put a 6502 in his Apple II was because it was cheap.

In order to gain the most benefit from the 6502, an assembly-language programmer must understand these idiosyncrasies and us them to his or her advantage.

Read the rest of this entry »