MOS Technology 6502

From Free net encyclopedia

(Redirected from 6502)

The MOS Technology 6502 is an 8-bit microprocessor designed by MOS Technology in 1975. When it was introduced it was the least expensive full featured CPU on the market by far, at about 1/6th the price, or less, of competing designs from larger companies such as Motorola and Intel. It was nevertheless faster than most of them, and, along with the Zilog Z80, sparked off a series of computer projects* that would eventually result in the home computer revolution of the 1980s. The 6502 design was originally second-sourced by Rockwell and Synertek and later licensed to a number of companies; it is still made for embedded systems.

(* See the list of home computers by category, which clearly shows the market divide between the 6502 and the Z80.)Image:MOS 6502AD 4585 top.jpg

Contents

History and use

The 6502 was designed primarily by the same team that had designed the Motorola 6800. After quitting Motorola en-masse, they quickly designed the 6501, a completely new design that was nevertheless pin-compatible with the 6800. Motorola sued immediately, and although today the case would have been dismissed out of hand, the damage to MOS was enough for them to agree to stop producing the 6501.

The result was the "lawsuit-compatible" 6502, differing only by a pinout re-arrangement unusable in a 6800 motherboard; now Motorola was apparently no longer interested. However this left MOS with the problem of getting new developers onto the system, so in response engineer Chuck Peddle designed the KIM-1 single-board computer. Much to their surprise, the KIM-1 sold in huge numbers to hobbyists and tinkerers as well as the engineers it was intended for. The related Rockwell AIM 65 control/training/development system also did well. Yet another roughly similar design was the Synertek SYM-1.

The 6502 was released to the market in September 1975 at $25, while the 6800 and Intel 8008 were selling for $179. At first many people thought it was some sort of a scam, but before the show was over both Motorola and Intel had dropped their prices to $79. Instead of saving them, the 6502 was now legitimized and started selling by the hundreds.

One of the first "public" uses for the design was the Atari 2600 videogame console. The 2600 used an offshoot of the 6502 called the 6507, which had fewer pins and could address only 8 KB of RAM as a result. Millions would be sold in this form. The 6502 was next used in the Apple II family, and then quickly appeared in various Commodore and Atari home computers, the BBC Micro family, and a huge number of other designs now lost to history. The 6510, a direct successor to the 6502 with a digital I/O port and a tristate bus, was the CPU utilized in the extremely popular Commodore 64 home computer.

Another important use of the 6502 was in the Nintendo Famicom, a Japanese video game console. Its North American and European equivalent, the Nintendo Entertainment System, also got the 6502. The 6502 used in the NES was a modified version (called 2A03 in NTSC consoles and 2A07 in PAL consoles, the difference being the clock divider ratio) that was produced solely for Nintendo. The custom NES processor lacked the 6502's decimal mode, but added 22 memory-mapped registers for sound generation, joypad reading, and sprite DMA.

The efficient design of the 6502 also inspired the principal designers of the ARM RISC processor, and so the legacy of the 6502 may be said to transcend the original processor (family) since its spirit lives on in the ARM design, used in several desktop computers as well as a plethora of handheld and other embedded systems, and sold as an IP block to be used in Systems-on-chip products.

Description

The 6502 is an 8-bit processor with a 16-bit address bus. The internal logic runs at the same speed as the external clock rate, but the seemingly slow clock speeds (typically in the neighborhood of 1 or 2 MHz) were actually competitive with other CPUs running significantly faster. This is because the 6502 is a pipelined static processor, while most other CPUs of the era were microcoded and had internal speeds comparable with the 6502. (The Z80 internal clock, for instance, was divided by four.) Although this may sound like a "trick", it had the side effect of lowering the speed requirement of the peripherals attached to the CPU, thus lowering overall system cost; an important factor in getting design wins in the very price sensitive game console and home computer markets.Image:MOS6502.svg

Unlike the Intel 8080 and similar microprocessors, the 6502 had very few registers. At the time RAM was faster than CPUs, so it made sense to optimize for RAM access rather than increase the number of registers on a chip. Indeed, the internal design of the 6502 requires it to perform a read or write access to memory for each clock cycle. Inside was one 8-bit accumulator register (A), two 8-bit index registers (X and Y), an 8-bit processor status register (P), an 8-bit stack pointer (S), and a 16-bit program counter (PC). The subroutine call/scratchpad stack's address space was hardwired to memory page $01, i.e. the address range $0100$01FF (256511). Software access to the stack was done via four implied addressing mode instructions whose function were to push or pop (pull) the accumulator or the processor status register.

The chip used the index and stack registers effectively with several addressing modes, including a fast "direct page" or "zero page" mode that accessed memory locations from address 0 to 255 with a single 8-bit address (it didn't have to fetch a second byte for the address) – code for the 6502 used the zero page much as code for other processors would have used registers. In most 6502-based microcomputers with an operating system, the OS itself used almost the entire zero page, leaving perhaps a handful of locations for the user.

Addressing modes also included implied (1 byte instructions); absolute (3 bytes); indexed absolute (3 bytes); indexed zero-page (2 bytes); relative (2 bytes); accumulator (1); indirect,x and indirect,y (2); and immediate (2). Absolute mode was a general-purpose mode. Relative was used for conditional branch instructions, which could move the program counter 126 bytes backwards or 129 bytes forwards (commonly incorrectly documented as being 128 and 127 respectively). Accumulator mode used the accumulator as an effective address, and didn't need any operand data. Immediate mode used an 8-bit literal operand.

The indirect modes were useful for array processing and other looping. With the indirect,y mode, the 8-bit Y register was added to a 16-bit base located in zero page memory (a byte in the opcode denoted the zero page location). The 8-bit Y register was used as an offset rather than 'normal' index register usage. Incrementing Y in order to walk the array was a two-cycle 8-bit operation, even though the array might be located anywhere in 16-bit address space (given the 16-bit base read from the zero page). This is where the 6502 differs most from the Motorola 6800. A superficial glance at the 6502's specs telling that there are only 8-bit index registers is thus quite misleading. With the less frequently used indirect,x mode the effective address for the operation was found at the zero page address formed by adding the second byte of the instruction to the contents of the X register.

See the Hello world! article for a simple but characteristic example of 6502 assembly language.

Dubious features

  • 6502s are almost notorious for having a variety of undocumented instructions, which vary from one chip manufacturer to the next. The 6502's instruction decoding is implemented in a hardwired logic array (similar to a programmable logic array) which is only defined for 151 of the 255 available opcodes. The remaining 105 trigger strange and hard-to-predict actions (like the processor immediately crashing; performing several valid instructions at once; or simply doing nothing, as far as has been discovered). All of the undefined opcodes were eventually replaced by NOP instructions in the subsequent 65C02 CMOS version (although with varying byte sizes and execution times).
  • The 6502's memory indirect jump instruction, JMP (<address low-word>), was broken. If <address low-word> was hex xxFF (i.e. any word ending in FF), the processor would not jump to the address stored in xxFF and xxFF+1, but rather the one in xxFF and xx00. The 6510 did not fix this bug, nor was it fixed in any of the other NMOS versions of the 6502 such as the 8502 and the 2A03. Bill Mensch at the Western Design Center was the first to fix it, in the 65C02 CMOS derivative; he then went on to design the 65816 processor, a 16-bit successor to the 65C02 as well as a hybrid offshoot called the 65802 which was a 65816 with a 64 KB address space in a 65(C)02 pin-compatible package.
  • Simultaneous appearance of NMI (non-maskable) and IRQ (maskable) interrupts caused the latter to be ignored.
  • Three of the status flags (N - negative, V - overflow and Z - zero) were invalid after performing arithmetic operation in BCD mode. It also was fixed in CMOS derivatives.

Acceleration

Many users of 1 MHz 6502-based systems soon wished their computers could go faster. A number of companies sold replacement hardware to speed up those systems. Generally, 6502 system accelerators were based on:

  • 6502 or 65C02 chips running at a faster clock rate
  • 65C816 chips in 6502 emulation mode, running at a much faster clock rate (up to 20 MHz)
  • 4 MHz and 8 MHz Zip Chip processors, made by Zip Technology, and 10 MHz Rocket Chips, made by Bits and Pieces, all using onboard cache RAM and proprietary glue logic to speed up processing while remaining compatible with a 1 MHz motherboard. Zip Technology's patent #4,794,523 eventually forced Bits and Pieces to cease manufacturing of the Rocket Chip.

6502 trivia

  • Bender, a fictional android "industrial robot" manufactured in 2998 AD, and a main character in the animated TV series Futurama, was revealed to have a 6502 as his "brain", in the episode "Fry & the Slurm Factory."

See also

References

  • Leventhal, Lance A. (1986). 6502 Assembly Language Programming 2nd Edition. Osborne/McGraw-Hill. ISBN 007881216X.
  • Leventhal, Lance A. (1982). 6502 Assembly Language Subroutines. Osborne/McGraw-Hill. ISBN 0931988594.
  • Mansfield, Richard (1983). Machine Language For Beginners. Personal Computer Machine Language Programming For The Atari, VIC, Apple, Commodore 64, And PET/CBM Computers (or, Machine Language Programming For BASIC Language Programmers). Greensboro, North Carolina: Compute! Publications, Inc. Copyright © 1983, Small System Services, Inc. ISBN 0-942386-11-6.
  • Zaks, Rodnay (1983). Programming the 6502 (Fourth Edition). Sybex, Inc. ISBN 0-89588-135-7.
  • Zaks, Rodnay (1982). Advanced 6502 Programming. Sybex, Inc. ISBN 0-89588-089-X.

External links


This article was originally based on material from the Free On-line Dictionary of Computing, which is licensed under the GFDL.
Template:MOS CPUde:MOS Technologies 6502

es:MOS 6502 fr:MOS Technology 6502 ko:MOS 6502 it:MOS Technology 6502 nl:6502 (processor) ja:6502 pl:MOS6502 ru:MOS Technology 6502 fi:MOS 6502 sv:MOS Technology 6502