MOS Technology 6502
Encyclopedia
The MOS Technology 6502 is an 8-bit
microprocessor
that was designed by Chuck Peddle
and Bill Mensch
for MOS Technology
in 1975. When it was introduced, it was the least expensive full-featured microprocessor on the market by a considerable margin, costing less than one-sixth the price of competing designs from larger companies such as Motorola
and Intel. It was nevertheless fully comparable with them and, along with the Zilog Z80
, sparked 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. Soon after the 6502's introduction, MOS Technology was bought outright by Commodore International
, who continued to sell the chip to other manufacturers.
. One of the designers, Chuck Peddle
, traveled around with the 6800 to introduce it to potential industrial customers. At the time it was targeted at the embedded market, and although their presentations sparked interest, the price, at about , was simply too high to be widely used. When he asked what sort of price would make the product useful, they settled on . Peddle returned to Motorola and proposed producing a low-cost product to attack this market, but found that management was uninterested; the 6800 was generating nice profits, there seemed to be no reason to change their sales efforts.
Undaunted, Peddle started working on such a design on his own. The new design was similar to the 6800 in that it also used a small number of processor register
s with a single accumulator
. The new design fixed one of the 6800's greatest problems, and allowed the accumulator and index registers to be used together as inputs and offsets. Other additions included the ability to perform binary coded decimal arithmetic and on-chip clock generation; only a single external clock signal was needed, and the new CPU could itself supply clock signals to other chips in a system, eliminating the need for a number of external components.
As the effort continued, the design team grew increasingly unhappy with management's lack of support. At the same time, management grew increasingly upset with the team spending time on a project they didn't support. Eventually Peddle was sent an official memo from management telling him to stop working on the low-cost design. In response, much of the original 6800 design team resigned en masse and went looking for a company that would be interested in building their new design.
as a second-source for Texas Instruments
calculator chips, but had since branched out to produce runs for a number of different companies. One of their recent products at the time was a single-chip implementation of the popular Pong
video game. The existing MOS engineers were not pleased to find an entire new team parachuted into their company. They were even more upset when they learned that the team would be cut in on part of any profits the new design generated.
At MOS, the Motorola team quickly designed the 6501, the first member of the 65xx series
of microprocessors and the first to be sold for . The new processor was designed to be pin-compatible with the 6800. This allowed it to be plugged into motherboard
s designed for the Motorola processor, like the MEK6800D2
, although its instruction set was different. It offered several addressing mode
s not available on the 6800. The 6501 is an eight-bit microprocessor
operating at using an NMOS
process. It has a 16-bit address bus capable of addressing of memory.
Motorola sued immediately, and MOS agreed to stop producing the 6501 and went back to the drawing board. The result was the "lawsuit-compatible" 6502, which was by design unusable in a 6800 motherboard but otherwise identical to the 6501. Motorola had no objection to this version. MOS was forced to pay the legal costs and promise to destroy every 6501 they had manufactured. The 6502 also added a two-phase clock generator, so it only needed a single phase clock input, simplifying system design.
However, this left MOS with the problem of getting developers to try their processor, so Peddle designed the MDT-650 (for "microcomputer development terminal") single-board computer
. Another group inside the company designed the KIM-1
, which was sold semi-complete and could be turned into a usable system with the addition of a 3rd party computer terminal
and compact cassette
drive. Much to their surprise, the KIM-1 sold well to hobbyists and tinkerers, as well as to the engineers it was intended for. The related Rockwell AIM 65 control/training/development system also did well. The software in the AIM 65 was based on that in the MDT. Another roughly similar product was the Synertek SYM-1
.
were selling for . At first many people thought the new chip's price was a hoax or a mistake, but while the show was still ongoing both Motorola and Intel had dropped their chips to . These price reductions legitimized the 6502, which started selling by the hundreds.
One of the first "public" uses for the design was the Apple I computer, introduced in 1976. The 6502 was next used in the Atari 2600
, Commodore PET
and the Apple II, all released in 1977. It was later used in the Atari
home computers, the BBC Micro
family, the Commodore VIC-20
and a large number of other designs both for home computers and business, such as Ohio Scientific
and Oric. The 6510
, a direct successor of the 6502 with a digital I/O port and a tri-state address bus, was the CPU
utilized in the Commodore 64
home computer. (Commodore's disk drive, the 1541
, had a processor of its own—it too was a 6502.)
Another important use of the 6500 family was in video games. The first to make use was the Atari 2600
video game console
. The 2600 used an offshoot of the 6502 called the 6507
, which had fewer pins and, as a result, could address only 8 KB
of memory. Millions of the Atari consoles would be sold, each with a MOS processor. Another significant use was by the Nintendo Famicom
, a Japan
ese video game console. Its international equivalent, the Nintendo Entertainment System
, also used the processor. The 6502 used in the NES was a second source
version by Ricoh
, a partial system-on-a-chip
, that lacked the binary-coded decimal
mode but added 22 memory-mapped registers (and on-die hardware) for sound generation, joypad reading, and sprite
list DMA
. Called 2A03 in NTSC
consoles and 2A07 in PAL
consoles (the difference being the memory divider
ratio and a lookup table for audio sample rates), this processor was produced exclusively for Nintendo
.
of . 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 despite the slow clock speeds (typically in the neighborhood of 1 to 2 MHz), the 6502's performance was actually competitive with other CPUs using significantly faster clocks. This is partly due to a simplistic state machine implemented by combinatorial (clockless) logic to a greater extent than in many other designs; the two phase clock (supplying two synchronizations per cycle) can thereby control the whole machine-cycle directly. Like most simple CPUs of the era, the dynamic NMOS
6502 chip was not sequenced by a microcode ROM but used a PLA
(which occupied about 15% of the chip area) for instruction decoding and sequencing. Like most eight-bit microprocessors, the chip does some limited overlapping of fetching and execution.
The low clock frequency moderated the speed requirement of memory and peripherals attached to the CPU, as only about 50% of the clock cycle was available for memory access (due to the asynchronous design, this percentage varied strongly among chip versions). This was critical at a time when affordable memory had access times in the range . The original NMOS
6502 was minimalistically engineered and efficiently manufactured and therefore cheap—an important factor in getting design wins in the very price-sensitive game console and home computer markets.Like its precursor, the Motorola
6800
, the 6502 has very few registers
. At the time the processor was designed, the number of transistors that could be economically put on a chip was very constrained (around a few thousand), so it made sense to rely on RAM instead of allocating expensive NMOS
chip area for CPU
registers.
The 6502's registers included one 8-bit accumulator
register (A), two 8-bit index register
s (X and Y), an 8-bit processor status register
(P), an 8-bit stack pointer
(S), and a 16-bit program counter
(PC). The stack's address space was hardwired to memory page $01, i.e. the address range $0100–$01FF (256–511). Software access to the stack was done via four implied addressing mode instructions whose functions were to push or pop (pull) the accumulator or the processor status register. The same stack was also used for subroutine calls via the JSR (Jump to Subroutine) and RTS (Return from Subroutine) instructions, and for interrupt
handling.
The chip used the index and stack registers effectively with several addressing mode
s, including a fast "direct page" or "zero page
" mode, similar to that found on the PDP-8
, that accessed memory locations from address 0 to 255 with a single 8-bit address (saving the cycle normally required to fetch the high-order byte of the address)—code for the 6502 used the zero page much as code for other processors would have used registers. On some 6502-based microcomputers with an operating system, the OS
would use most of zero page, leaving only a handful of locations for the user.
Addressing mode
s 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. Branch instructions used a signed 8-bit offset relative to the instruction after the branch; the numerical range -128..127 therefore translates to 128 bytes backward and 127 bytes forward from the instruction following the branch (which is 126 bytes backward and 129 bytes forward from the start of the branch instruction). Accumulator mode used the accumulator as an effective address, and did not 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 5/6 cycle "(indirect),y" mode, the 8-bit Y register was added to a 16-bit base address in zero page which was located by a single byte following the opcode. The Y register was therefore an index-register in the sense that it was used to hold an actual index (as opposed to the X register in the 6800 where a base address was directly stored and to which an immediate offset could be added). Incrementing the index register to walk the array byte-wise took only two additional cycles. 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. Using the indexed modes, the zero page effectively acted as a set of 128 additional (though very slow) address registers.
The 6502 is capable of performing addition and subtraction in binary or binary coded decimal. Placing the CPU into BCD mode with the SED instruction results in decimal arithmetic, in which $99 + $01 would result in $00 and the carry flag being set. In binary mode (CLD), the same operation would result in $9A and the carry flag being cleared. Other than Atari BASIC
, BCD mode was seldom used in home computer applications.
A Byte magazine
article once referred to the 6502 as "the original RISC processor," due to its efficient, simplistic, and nearly orthogonal instruction set
(most instructions work with most addressing modes), as well as its 256 zero-page "registers". The 6502 is technically not a RISC design however, as arithmetic operations can read any memory cell (not only zero-page), and some instructions (inc, rol etc.) even modify memory contrary to the basic load/store philosophy of RISC. Furthermore, orthogonality
is equally often associated with "CISC
". However the 6502 performed reasonably well compared to other contemporary processors such as the Z80, which used a much faster clock rate, and the 6502 has been credited as being inspirational to RISC processors such as the ARM
. However the inspiration from the 6502 was related to the simple implementation, rather than the architecture, which is very different to that of the ARM. Also Sophie Wilson
, who designed the instruction set for the ARM, has stated that the 6502 has little in common with the ARM processor.
See the Hello world! article for a simple but characteristic example of 6502 assembly language
.
(NMI) input is edge sensitive, which means that if the source of an NMI holds the line low, further NMIs after the first are effectively disabled.
The simultaneous assertion of the NMI (non-maskable) and IRQ
(maskable) hardware interrupt lines causes IRQ to be ignored. However, if the IRQ line remains asserted
after the servicing of the NMI, the processor will immediately respond to IRQ, as IRQ is level sensitive. Thus a sort of built-in interrupt priority was established in the 6502 design.
The "Break" flag of the processor is very different from the other flag bits. It has no flag setting, resetting, and testing instructions of its own, and is not handled by the PHP and PLP instructions either. It exists only on the stack, where BRK and PHP always write a 1, while IRQ and NMI always write a 0.
The "SO" input pin, when asserted, would set the processor's overflow status bit (deasserting it does not clear the overflow bit, however). This can be used by a high-speed polling
device driver, which can poll the hardware once in only three cycles by using a Branch-on-oVerflow-Clear (BVC) instruction that branches to itself; for example the Commodore 1541
and other Commodore
floppy disk
drives use it to detect as quickly as possible whether the serializer
is ready to accept or provide another byte of disk data, as a normal test-and-branch loop takes seven cycles which is too slow in that particular application. Obviously great care must be used in the device driver and the associated system design, as spurious assertion of the overflow bit could ruin arithmetic processing.
, and relied on an external clock. (The 6502 used an internal clock generator to generate the
Phase 1 and Phase 2 clocks.) This was used to advantage in some designs where the clocks could be run asymmetrically, increasing overall CPU performance.
designed and produced the 65C816 processor, a 16-bit successor to the 65C02, as well as a hybrid offshoot called the 65C802 which was a 65C816 core with a 64 KB address space in a 65(C)02 pin-compatible package—it could be plugged into a 6502 board and would function as a 65C02, or it could be configured via software to expose its 16 bit accumulator
and index registers. Few 65C802 parts were sold, and the chip is no longer produced.
The 65C816 was the core of the widely popular Super Nintendo Entertainment System
, and the Apple IIGS
. The 65C816 is still widely used, both as a discrete
processor and as the core of a microcontroller
.
Mitsubishi
(now Renesas Technology) made a line of 16-bit microcontrollers with an architecture very similar to the 65816, though it was not 100% compatible.
Synertek
published a data sheet and application notes on the SY6516, a 16-bit derivative of the 6502, but the part was never introduced.
(1984), starring Arnold Schwarzenegger
, the audience at one point is treated to a view through the T-800
Model-101 robot character's eye/camera
display with some 6502 assembly
/machine code
program fragments scrolling
down the screen. The program was listing the Apple DOS
3.3 disassembled
program listing. Also shown is the output from a run of an Apple
checksum
program called KEY PERFECT 4.0, published in Nibble magazine
.
Bender, a fictional android "industrial robot
" manufactured in 2998, and a main character in the animated TV series Futurama
created by Matt Groening
, was revealed to have a 6502 as his "brain" in the episode "Fry and the Slurm Factory
". David X. Cohen
(the head writer and executive producer of Futurama
) has claimed in an interview with IEEE Spectrum
that he and friends David Borden and David Schiminovich wrote an assembly language
compiler
(for a custom language they created named "FLEET") for the Apple II Plus
, which uses the 6502, while at high school, and confirmed that this led him to include the reference in the show.
Instruction set features:
Emulators and simulators:
Early 6502 computers:
Hardware accelerators:
Hardware:
8-bit
The first widely adopted 8-bit microprocessor was the Intel 8080, being used in many hobbyist computers of the late 1970s and early 1980s, often running the CP/M operating system. The Zilog Z80 and the Motorola 6800 were also used in similar computers...
microprocessor
Microprocessor
A microprocessor incorporates the functions of a computer's central processing unit on a single integrated circuit, or at most a few integrated circuits. It is a multipurpose, programmable device that accepts digital data as input, processes it according to instructions stored in its memory, and...
that was designed by Chuck Peddle
Chuck Peddle
Charles Ingerham Peddle is an American electrical engineer best known as the main designer of the MOS Technology 6502 microprocessor; the KIM-1 SBC; and its successor the Commodore PET personal computer, both based on the 6502....
and Bill Mensch
Bill Mensch
American engineer William David Mensch, Jr., born 9 February 1945 in Quakertown, Pennsylvania, USA, is the founder, chairman and CEO of the Western Design Center of Mesa, Arizona...
for MOS Technology
MOS Technology
MOS Technology, Inc., also known as CSG , was a semiconductor design and fabrication company based in Norristown, Pennsylvania, in the United States. It is most famous for its 6502 microprocessor, and various designs for Commodore International's range of home computers.-History:MOS Technology, Inc...
in 1975. When it was introduced, it was the least expensive full-featured microprocessor on the market by a considerable margin, costing less than one-sixth the price of competing designs from larger companies such as Motorola
Motorola
Motorola, Inc. was an American multinational telecommunications company based in Schaumburg, Illinois, which was eventually divided into two independent public companies, Motorola Mobility and Motorola Solutions on January 4, 2011, after losing $4.3 billion from 2007 to 2009...
and Intel. It was nevertheless fully comparable with them and, along with the Zilog Z80
Zilog Z80
The Zilog Z80 is an 8-bit microprocessor designed by Zilog and sold from July 1976 onwards. It was widely used both in desktop and embedded computer designs as well as for military purposes...
, sparked a series of computer projects that would eventually result in the home computer
Home computer
Home computers were a class of microcomputers entering the market in 1977, and becoming increasingly common during the 1980s. They were marketed to consumers as affordable and accessible computers that, for the first time, were intended for the use of a single nontechnical user...
revolution
Microcomputer revolution
The microcomputer revolution is a phrase used to describe the rapid advances of microprocessor-based computers from esoteric hobby projects to a commonplace fixture of homes in industrial societies...
of the 1980s. The 6502 design was originally second-sourced
Second source
In the electronics industry, a second source is a company that is licensed to manufacture and sell components originally designed by another company ....
by Rockwell
Rockwell International
Rockwell International was a major American manufacturing conglomerate in the latter half of the 20th century, involved in aircraft, the space industry, both defense-oriented and commercial electronics, automotive and truck components, printing presses, valves and meters, and industrial automation....
and Synertek
Synertek
Synertek, Inc. was an American semiconductor manufacturer founded in 1973. The initial founding group consisted of Bob Schreiner , Dan Floyd, Zvi Grinfas, Jack Balletto, and Gunnar Wetlesen. The manufacturing technology was MOS/LSI...
and later licensed to a number of companies. Soon after the 6502's introduction, MOS Technology was bought outright by Commodore International
Commodore International
Commodore is the commonly used name for Commodore Business Machines , the U.S.-based home computer manufacturer and electronics manufacturer headquartered in West Chester, Pennsylvania, which also housed Commodore's corporate parent company, Commodore International Limited...
, who continued to sell the chip to other manufacturers.
Origins at Motorola
The 6502 was designed primarily by the same engineering team that had designed the Motorola 6800Motorola 6800
The 6800 was an 8-bit microprocessor designed and first manufactured by Motorola in 1974. The MC6800 microprocessor was part of the M6800 Microcomputer System that also included serial and parallel interface ICs, RAM, ROM and other support chips...
. One of the designers, Chuck Peddle
Chuck Peddle
Charles Ingerham Peddle is an American electrical engineer best known as the main designer of the MOS Technology 6502 microprocessor; the KIM-1 SBC; and its successor the Commodore PET personal computer, both based on the 6502....
, traveled around with the 6800 to introduce it to potential industrial customers. At the time it was targeted at the embedded market, and although their presentations sparked interest, the price, at about , was simply too high to be widely used. When he asked what sort of price would make the product useful, they settled on . Peddle returned to Motorola and proposed producing a low-cost product to attack this market, but found that management was uninterested; the 6800 was generating nice profits, there seemed to be no reason to change their sales efforts.
Undaunted, Peddle started working on such a design on his own. The new design was similar to the 6800 in that it also used a small number of processor register
Processor register
In computer architecture, a processor register is a small amount of storage available as part of a CPU or other digital processor. Such registers are addressed by mechanisms other than main memory and can be accessed more quickly...
s with a single accumulator
Accumulator (computing)
In a computer's central processing unit , an accumulator is a register in which intermediate arithmetic and logic results are stored. Without a register like an accumulator, it would be necessary to write the result of each calculation to main memory, perhaps only to be read right back again for...
. The new design fixed one of the 6800's greatest problems, and allowed the accumulator and index registers to be used together as inputs and offsets. Other additions included the ability to perform binary coded decimal arithmetic and on-chip clock generation; only a single external clock signal was needed, and the new CPU could itself supply clock signals to other chips in a system, eliminating the need for a number of external components.
As the effort continued, the design team grew increasingly unhappy with management's lack of support. At the same time, management grew increasingly upset with the team spending time on a project they didn't support. Eventually Peddle was sent an official memo from management telling him to stop working on the low-cost design. In response, much of the original 6800 design team resigned en masse and went looking for a company that would be interested in building their new design.
Moving to MOS and the 6501
The team was soon in negotiations with MOS Technology, at that time a small fab who produced chips for 3rd parties with limited internal design capability. The company had originally been set up by Allen-BradleyAllen-Bradley
Allen-Bradley is the brand-name of a line of Factory Automation Equipment manufactured by Rockwell Automation . The company, with revenues of approximately US$4.5 billion in 2006, manufactures programmable automation controllers , human-machine interfaces, sensors, safety components and systems,...
as a second-source for Texas Instruments
Texas Instruments
Texas Instruments Inc. , widely known as TI, is an American company based in Dallas, Texas, United States, which develops and commercializes semiconductor and computer technology...
calculator chips, but had since branched out to produce runs for a number of different companies. One of their recent products at the time was a single-chip implementation of the popular Pong
Pong
Pong is one of the earliest arcade video games, and is a tennis sports game featuring simple two-dimensional graphics. While other arcade video games such as Computer Space came before it, Pong was one of the first video games to reach mainstream popularity...
video game. The existing MOS engineers were not pleased to find an entire new team parachuted into their company. They were even more upset when they learned that the team would be cut in on part of any profits the new design generated.
At MOS, the Motorola team quickly designed the 6501, the first member of the 65xx series
MOS Technology 65xx
MOS Technology 65xx is a family of 8-bit microprocessors from MOS Technology, based on the Motorola 6800 . The 65xx family most notably included the 6502, used in several home computers such as the Commodore PET and VIC-20, the Apple II, and the Atari 800.One popular 6502 based computer, the...
of microprocessors and the first to be sold for . The new processor was designed to be pin-compatible with the 6800. This allowed it to be plugged into motherboard
Motherboard
In personal computers, a motherboard is the central printed circuit board in many modern computers and holds many of the crucial components of the system, providing connectors for other peripherals. The motherboard is sometimes alternatively known as the mainboard, system board, or, on Apple...
s designed for the Motorola processor, like the MEK6800D2
MEK6800D2
The MEK6800D2 was a development board for the Motorola 6800 microprocessor, produced by Motorola in 1976. It featured a keyboard with hexadecimal keys and a LED display, but also featured an RS-232 asynchronous serial interface for a Teletype or other terminal...
, although its instruction set was different. It offered several addressing mode
Addressing mode
Addressing modes are an aspect of the instruction set architecture in most central processing unit designs. The various addressing modes that are defined in a given instruction set architecture define how machine language instructions in that architecture identify the operand of each instruction...
s not available on the 6800. The 6501 is an eight-bit microprocessor
Microprocessor
A microprocessor incorporates the functions of a computer's central processing unit on a single integrated circuit, or at most a few integrated circuits. It is a multipurpose, programmable device that accepts digital data as input, processes it according to instructions stored in its memory, and...
operating at using an NMOS
NMOS logic
N-type metal-oxide-semiconductor logic uses n-type metal-oxide-semiconductor field effect transistors to implement logic gates and other digital circuits...
process. It has a 16-bit address bus capable of addressing of memory.
Motorola sued immediately, and MOS agreed to stop producing the 6501 and went back to the drawing board. The result was the "lawsuit-compatible" 6502, which was by design unusable in a 6800 motherboard but otherwise identical to the 6501. Motorola had no objection to this version. MOS was forced to pay the legal costs and promise to destroy every 6501 they had manufactured. The 6502 also added a two-phase clock generator, so it only needed a single phase clock input, simplifying system design.
However, this left MOS with the problem of getting developers to try their processor, so Peddle designed the MDT-650 (for "microcomputer development terminal") single-board computer
Single-board computer
A single-board computer is a complete computer built on a single circuit board, with microprocessor, memory, input/output and other features required of a functional computer. Unlike a typical personal computer, an SBC may not include slots into which accessory cards may be plugged...
. Another group inside the company designed the KIM-1
KIM-1
The KIM-1, short for Keyboard Input Monitor, was a small 6502-based single-board computer developed and produced by MOS Technology, Inc. and launched in 1976...
, which was sold semi-complete and could be turned into a usable system with the addition of a 3rd party computer terminal
Computer terminal
A computer terminal is an electronic or electromechanical hardware device that is used for entering data into, and displaying data from, a computer or a computing system...
and compact cassette
Compact Cassette
The Compact Cassette, often referred to as audio cassette, cassette tape, cassette, or simply tape, is a magnetic tape sound recording format. It was designed originally for dictation, but improvements in fidelity led the Compact Cassette to supplant the Stereo 8-track cartridge and reel-to-reel...
drive. Much to their surprise, the KIM-1 sold well to hobbyists and tinkerers, as well as to the engineers it was intended for. The related Rockwell AIM 65 control/training/development system also did well. The software in the AIM 65 was based on that in the MDT. Another roughly similar product was the Synertek SYM-1
SYM-1
The SYM-1 was a single board "trainer" computer produced by Synertek circa 1978. Originally called the VIM-1 , that name was changed for legal reasons sometime between April and August 1978....
.
Introducing the 6502
The 6502 was introduced at at the Wescon show in September 1975. The company had an off-floor suite with a big jar full of the chips. However with this early run they only had a handful of working ones. To give the appearance of larger quantities, the bottom of the jar was stuffed with defective chips, and only the ones at the top of the jar worked. At the same show the 6800 and Intel 8080Intel 8080
The Intel 8080 was the second 8-bit microprocessor designed and manufactured by Intel and was released in April 1974. It was an extended and enhanced variant of the earlier 8008 design, although without binary compatibility...
were selling for . At first many people thought the new chip's price was a hoax or a mistake, but while the show was still ongoing both Motorola and Intel had dropped their chips to . These price reductions legitimized the 6502, which started selling by the hundreds.
One of the first "public" uses for the design was the Apple I computer, introduced in 1976. The 6502 was next used in the Atari 2600
Atari 2600
The Atari 2600 is a video game console released in October 1977 by Atari, Inc. It is credited with popularizing the use of microprocessor-based hardware and cartridges containing game code, instead of having non-microprocessor dedicated hardware with all games built in...
, Commodore PET
Commodore PET
The Commodore PET was a home/personal computer produced from 1977 by Commodore International...
and the Apple II, all released in 1977. It was later used in the Atari
Atari 8-bit family
The Atari 8-bit family is a series of 8-bit home computers manufactured from 1979 to 1992. All are based on the MOS Technology 6502 CPU and were the first home computers designed with custom coprocessor chips...
home computers, the BBC Micro
BBC Micro
The BBC Microcomputer System, or BBC Micro, was a series of microcomputers and associated peripherals designed and built by Acorn Computers for the BBC Computer Literacy Project, operated by the British Broadcasting Corporation...
family, the Commodore VIC-20
Commodore VIC-20
The VIC-20 is an 8-bit home computer which was sold by Commodore Business Machines. The VIC-20 was announced in 1980, roughly three years after Commodore's first personal computer, the PET...
and a large number of other designs both for home computers and business, such as Ohio Scientific
Ohio Scientific
Ohio Scientific Inc. was a United States computer company that built and marketed computers from the late 1970s to the early 1980s...
and Oric. The 6510
MOS Technology 6510
thumb|300px|Image of the internals of a [[Commodore 64]] showing the 6510 CPU . The chip on the right is the [[MOS Technology SID|6581 SID]]...
, a direct successor of the 6502 with a digital I/O port and a tri-state address bus, was the CPU
Central processing unit
The central processing unit is the portion of a computer system that carries out the instructions of a computer program, to perform the basic arithmetical, logical, and input/output operations of the system. The CPU plays a role somewhat analogous to the brain in the computer. The term has been in...
utilized in the Commodore 64
Commodore 64
The Commodore 64 is an 8-bit home computer introduced by Commodore International in January 1982.Volume production started in the spring of 1982, with machines being released on to the market in August at a price of US$595...
home computer. (Commodore's disk drive, the 1541
Commodore 1541
The Commodore 1541 , made by Commodore International, was the best-known floppy disk drive for the Commodore 64 home computer. The 1541 was a single-sided 170 kilobyte drive for 5¼" disks...
, had a processor of its own—it too was a 6502.)
Another important use of the 6500 family was in video games. The first to make use was the Atari 2600
Atari 2600
The Atari 2600 is a video game console released in October 1977 by Atari, Inc. It is credited with popularizing the use of microprocessor-based hardware and cartridges containing game code, instead of having non-microprocessor dedicated hardware with all games built in...
video game console
Video game console
A video game console is an interactive entertainment computer or customized computer system that produces a video display signal which can be used with a display device to display a video game...
. The 2600 used an offshoot of the 6502 called the 6507
MOS Technology 6507
The 6507 is an 8-bit microprocessor from MOS Technology, Inc.It is essentially a 6502 chip in a smaller, cheaper 28-pin package. To do this, A15 to A13 and some other signals such as the interrupt lines are not accessible...
, which had fewer pins and, as a result, could address only 8 KB
Kilobyte
The kilobyte is a multiple of the unit byte for digital information. Although the prefix kilo- means 1000, the term kilobyte and symbol KB have historically been used to refer to either 1024 bytes or 1000 bytes, dependent upon context, in the fields of computer science and information...
of memory. Millions of the Atari consoles would be sold, each with a MOS processor. Another significant use was by the Nintendo Famicom
Nintendo Entertainment System
The Nintendo Entertainment System is an 8-bit video game console that was released by Nintendo in North America during 1985, in Europe during 1986 and Australia in 1987...
, a Japan
Japan
Japan is an island nation in East Asia. Located in the Pacific Ocean, it lies to the east of the Sea of Japan, China, North Korea, South Korea and Russia, stretching from the Sea of Okhotsk in the north to the East China Sea and Taiwan in the south...
ese video game console. Its international equivalent, the Nintendo Entertainment System
Nintendo Entertainment System
The Nintendo Entertainment System is an 8-bit video game console that was released by Nintendo in North America during 1985, in Europe during 1986 and Australia in 1987...
, also used the processor. The 6502 used in the NES was a second source
Second source
In the electronics industry, a second source is a company that is licensed to manufacture and sell components originally designed by another company ....
version by Ricoh
Ricoh
or Ricoh, is a Japanese company that was established in 1936 on February 6th, as , a company in the RIKEN zaibatsu. Its headquarters is located in Ricoh Building in Chūō, Tokyo....
, a partial system-on-a-chip
System-on-a-chip
A system on a chip or system on chip is an integrated circuit that integrates all components of a computer or other electronic system into a single chip. It may contain digital, analog, mixed-signal, and often radio-frequency functions—all on a single chip substrate...
, that lacked the binary-coded decimal
Binary-coded decimal
In computing and electronic systems, binary-coded decimal is a digital encoding method for numbers using decimal notation, with each decimal digit represented by its own binary sequence. In BCD, a numeral is usually represented by four bits which, in general, represent the decimal range 0 through 9...
mode but added 22 memory-mapped registers (and on-die hardware) for sound generation, joypad reading, and sprite
Sprite (computer graphics)
In computer graphics, a sprite is a two-dimensional image or animation that is integrated into a larger scene...
list DMA
Direct memory access
Direct memory access is a feature of modern computers that allows certain hardware subsystems within the computer to access system memory independently of the central processing unit ....
. Called 2A03 in NTSC
NTSC
NTSC, named for the National Television System Committee, is the analog television system that is used in most of North America, most of South America , Burma, South Korea, Taiwan, Japan, the Philippines, and some Pacific island nations and territories .Most countries using the NTSC standard, as...
consoles and 2A07 in PAL
PAL
PAL, short for Phase Alternating Line, is an analogue television colour encoding system used in broadcast television systems in many countries. Other common analogue television systems are NTSC and SECAM. This page primarily discusses the PAL colour encoding system...
consoles (the difference being the memory divider
Memory divider
A memory divider is a ratio which is used to determine the operating clock frequency of computer memory in accordance with front side bus frequency, if the memory system is dependent on FSB clock speed. Along with memory latency timings, memory dividers are extensively used in overclocking memory...
ratio and a lookup table for audio sample rates), this processor was produced exclusively for Nintendo
Nintendo
is a multinational corporation located in Kyoto, Japan. Founded on September 23, 1889 by Fusajiro Yamauchi, it produced handmade hanafuda cards. By 1963, the company had tried several small niche businesses, such as a cab company and a love hotel....
.
Technical description
The MOS Technology 6502 is a process technology chip with and a die sizeDie (integrated circuit)
A die in the context of integrated circuits is a small block of semiconducting material, on which a given functional circuit is fabricated.Typically, integrated circuits are produced in large batches on a single wafer of electronic-grade silicon or other semiconductor through processes such as...
of . The 6502 is an 8-bit
8-bit
The first widely adopted 8-bit microprocessor was the Intel 8080, being used in many hobbyist computers of the late 1970s and early 1980s, often running the CP/M operating system. The Zilog Z80 and the Motorola 6800 were also used in similar computers...
processor with a 16-bit
16-bit
-16-bit architecture:The HP BPC, introduced in 1975, was the world's first 16-bit microprocessor. Prominent 16-bit processors include the PDP-11, Intel 8086, Intel 80286 and the WDC 65C816. The Intel 8088 was program-compatible with the Intel 8086, and was 16-bit in that its registers were 16...
address bus
Address bus
An address bus is a computer bus that is used to specify a physical address. When a processor or DMA-enabled device needs to read or write to a memory location, it specifies that memory location on the address bus...
. The internal logic runs at the same speed as the external clock rate, but despite the slow clock speeds (typically in the neighborhood of 1 to 2 MHz), the 6502's performance was actually competitive with other CPUs using significantly faster clocks. This is partly due to a simplistic state machine implemented by combinatorial (clockless) logic to a greater extent than in many other designs; the two phase clock (supplying two synchronizations per cycle) can thereby control the whole machine-cycle directly. Like most simple CPUs of the era, the dynamic NMOS
NMOS logic
N-type metal-oxide-semiconductor logic uses n-type metal-oxide-semiconductor field effect transistors to implement logic gates and other digital circuits...
6502 chip was not sequenced by a microcode ROM but used a PLA
Programmable logic array
A programmable logic array is a kind of programmable logic device used to implement combinational logic circuits. The PLA has a set of programmable AND gate planes, which link to a set of programmable OR gate planes, which can then be conditionally complemented to produce an output...
(which occupied about 15% of the chip area) for instruction decoding and sequencing. Like most eight-bit microprocessors, the chip does some limited overlapping of fetching and execution.
The low clock frequency moderated the speed requirement of memory and peripherals attached to the CPU, as only about 50% of the clock cycle was available for memory access (due to the asynchronous design, this percentage varied strongly among chip versions). This was critical at a time when affordable memory had access times in the range . The original NMOS
NMOS logic
N-type metal-oxide-semiconductor logic uses n-type metal-oxide-semiconductor field effect transistors to implement logic gates and other digital circuits...
6502 was minimalistically engineered and efficiently manufactured and therefore cheap—an important factor in getting design wins in the very price-sensitive game console and home computer markets.Like its precursor, the Motorola
Motorola
Motorola, Inc. was an American multinational telecommunications company based in Schaumburg, Illinois, which was eventually divided into two independent public companies, Motorola Mobility and Motorola Solutions on January 4, 2011, after losing $4.3 billion from 2007 to 2009...
6800
Motorola 6800
The 6800 was an 8-bit microprocessor designed and first manufactured by Motorola in 1974. The MC6800 microprocessor was part of the M6800 Microcomputer System that also included serial and parallel interface ICs, RAM, ROM and other support chips...
, the 6502 has very few registers
Processor register
In computer architecture, a processor register is a small amount of storage available as part of a CPU or other digital processor. Such registers are addressed by mechanisms other than main memory and can be accessed more quickly...
. At the time the processor was designed, the number of transistors that could be economically put on a chip was very constrained (around a few thousand), so it made sense to rely on RAM instead of allocating expensive NMOS
NMOS logic
N-type metal-oxide-semiconductor logic uses n-type metal-oxide-semiconductor field effect transistors to implement logic gates and other digital circuits...
chip area for CPU
Central processing unit
The central processing unit is the portion of a computer system that carries out the instructions of a computer program, to perform the basic arithmetical, logical, and input/output operations of the system. The CPU plays a role somewhat analogous to the brain in the computer. The term has been in...
registers.
The 6502's registers included one 8-bit accumulator
Accumulator (computing)
In a computer's central processing unit , an accumulator is a register in which intermediate arithmetic and logic results are stored. Without a register like an accumulator, it would be necessary to write the result of each calculation to main memory, perhaps only to be read right back again for...
register (A), two 8-bit index register
Index register
An index registerCommonly known as a B-line in early British computers. in a computer's CPU is a processor register used for modifying operand addresses during the run of a program, typically for doing vector/array operations...
s (X and Y), an 8-bit processor status register
Status register
A status register or flag register is a collection of flag bits for a processor. An example is the FLAGS register of the x86 architecture....
(P), an 8-bit stack pointer
Stack (data structure)
In computer science, a stack is a last in, first out abstract data type and linear data structure. A stack can have any abstract data type as an element, but is characterized by only three fundamental operations: push, pop and stack top. The push operation adds a new item to the top of the stack,...
(S), and a 16-bit program counter
Program counter
The program counter , commonly called the instruction pointer in Intel x86 microprocessors, and sometimes called the instruction address register, or just part of the instruction sequencer in some computers, is a processor register that indicates where the computer is in its instruction sequence...
(PC). The stack's address space was hardwired to memory page $01, i.e. the address range $0100–$01FF (256–511). Software access to the stack was done via four implied addressing mode instructions whose functions were to push or pop (pull) the accumulator or the processor status register. The same stack was also used for subroutine calls via the JSR (Jump to Subroutine) and RTS (Return from Subroutine) instructions, and for interrupt
Interrupt
In computing, an interrupt is an asynchronous signal indicating the need for attention or a synchronous event in software indicating the need for a change in execution....
handling.
The chip used the index and stack registers effectively with several addressing mode
Addressing mode
Addressing modes are an aspect of the instruction set architecture in most central processing unit designs. The various addressing modes that are defined in a given instruction set architecture define how machine language instructions in that architecture identify the operand of each instruction...
s, including a fast "direct page" or "zero page
Zero page
The zero page is the series of memory addresses at the absolute beginning of a computer's address space; that is, the page whose starting address is zero. The size of a "page" depends on the context, and the significance of zero-page memory versus higher addressed memory is highly dependent on...
" mode, similar to that found on the PDP-8
PDP-8
The 12-bit PDP-8 was the first successful commercial minicomputer, produced by Digital Equipment Corporation in the 1960s. DEC introduced it on 22 March 1965, and sold more than 50,000 systems, the most of any computer up to that date. It was the first widely sold computer in the DEC PDP series of...
, that accessed memory locations from address 0 to 255 with a single 8-bit address (saving the cycle normally required to fetch the high-order byte of the address)—code for the 6502 used the zero page much as code for other processors would have used registers. On some 6502-based microcomputers with an operating system, the OS
Operating system
An operating system is a set of programs that manage computer hardware resources and provide common services for application software. The operating system is the most important type of system software in a computer system...
would use most of zero page, leaving only a handful of locations for the user.
Addressing mode
Addressing mode
Addressing modes are an aspect of the instruction set architecture in most central processing unit designs. The various addressing modes that are defined in a given instruction set architecture define how machine language instructions in that architecture identify the operand of each instruction...
s 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. Branch instructions used a signed 8-bit offset relative to the instruction after the branch; the numerical range -128..127 therefore translates to 128 bytes backward and 127 bytes forward from the instruction following the branch (which is 126 bytes backward and 129 bytes forward from the start of the branch instruction). Accumulator mode used the accumulator as an effective address, and did not need any operand
Operand
In mathematics, an operand is the object of a mathematical operation, a quantity on which an operation is performed.-Example :The following arithmetic expression shows an example of operators and operands:3 + 6 = 9\;...
data. Immediate mode used an 8-bit literal operand.
The indirect modes were useful for array
Array data type
In computer science, an array type is a data type that is meant to describe a collection of elements , each selected by one or more indices that can be computed at run time by the program. Such a collection is usually called an array variable, array value, or simply array...
processing and other looping. With the 5/6 cycle "(indirect),y" mode, the 8-bit Y register was added to a 16-bit base address in zero page which was located by a single byte following the opcode. The Y register was therefore an index-register in the sense that it was used to hold an actual index (as opposed to the X register in the 6800 where a base address was directly stored and to which an immediate offset could be added). Incrementing the index register to walk the array byte-wise took only two additional cycles. 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. Using the indexed modes, the zero page effectively acted as a set of 128 additional (though very slow) address registers.
The 6502 is capable of performing addition and subtraction in binary or binary coded decimal. Placing the CPU into BCD mode with the SED instruction results in decimal arithmetic, in which $99 + $01 would result in $00 and the carry flag being set. In binary mode (CLD), the same operation would result in $9A and the carry flag being cleared. Other than Atari BASIC
Atari BASIC
Atari BASIC is a BASIC interpreter for the Atari 8-bit family of 6502-based home computers. The interpreter originally shipped on an 8 KB cartridge; on later XL/XE model computers it was built in, with an option to disable it, and started when the machines were booted with no other cartridges...
, BCD mode was seldom used in home computer applications.
A Byte magazine
Byte (magazine)
BYTE magazine was a microcomputer magazine, influential in the late 1970s and throughout the 1980s because of its wide-ranging editorial coverage...
article once referred to the 6502 as "the original RISC processor," due to its efficient, simplistic, and nearly orthogonal instruction set
Orthogonal instruction set
Orthogonal instruction set is a term used in computer engineering. A computer's instruction set is said to be orthogonal if any instruction can use data of any type via any addressing mode...
(most instructions work with most addressing modes), as well as its 256 zero-page "registers". The 6502 is technically not a RISC design however, as arithmetic operations can read any memory cell (not only zero-page), and some instructions (inc, rol etc.) even modify memory contrary to the basic load/store philosophy of RISC. Furthermore, orthogonality
Orthogonal instruction set
Orthogonal instruction set is a term used in computer engineering. A computer's instruction set is said to be orthogonal if any instruction can use data of any type via any addressing mode...
is equally often associated with "CISC
Complex instruction set computer
A complex instruction set computer , is a computer where single instructions can execute several low-level operations and/or are capable of multi-step operations or addressing modes within single instructions...
". However the 6502 performed reasonably well compared to other contemporary processors such as the Z80, which used a much faster clock rate, and the 6502 has been credited as being inspirational to RISC processors such as the ARM
ARM architecture
ARM is a 32-bit reduced instruction set computer instruction set architecture developed by ARM Holdings. It was named the Advanced RISC Machine, and before that, the Acorn RISC Machine. The ARM architecture is the most widely used 32-bit ISA in numbers produced...
. However the inspiration from the 6502 was related to the simple implementation, rather than the architecture, which is very different to that of the ARM. Also Sophie Wilson
Sophie Wilson
Sophie Wilson is a British computer scientist. She is known for designing the Acorn Micro-Computer, the first of a long line of computers sold by Acorn Computers Ltd, as well as the instruction set of the highly successful ARM processor.- Life and career :...
, who designed the instruction set for the ARM, has stated that the 6502 has little in common with the ARM processor.
See the Hello world! article for a simple but characteristic example of 6502 assembly language
Assembly language
An assembly language is a low-level programming language for computers, microprocessors, microcontrollers, and other programmable devices. It implements a symbolic representation of the machine codes and other constants needed to program a given CPU architecture...
.
Detailed behavior
The processor's non-maskable interruptNon-Maskable interrupt
A non-maskable interrupt is a computer processor interrupt that cannot be ignored by standard interrupt masking techniques in the system. It is typically used to signal attention for non-recoverable hardware errors...
(NMI) input is edge sensitive, which means that if the source of an NMI holds the line low, further NMIs after the first are effectively disabled.
The simultaneous assertion of the NMI (non-maskable) and IRQ
Interrupt request
The computing phrase "interrupt request" is used to refer to either the act of interrupting the bus lines used to signal an interrupt, or the interrupt input lines on a Programmable Interrupt Controller...
(maskable) hardware interrupt lines causes IRQ to be ignored. However, if the IRQ line remains asserted
Assertion (computing)
In computer programming, an assertion is a predicate placed in a program to indicate that the developer thinks that the predicate is always true at that place.For example, the following code contains two assertions:...
after the servicing of the NMI, the processor will immediately respond to IRQ, as IRQ is level sensitive. Thus a sort of built-in interrupt priority was established in the 6502 design.
The "Break" flag of the processor is very different from the other flag bits. It has no flag setting, resetting, and testing instructions of its own, and is not handled by the PHP and PLP instructions either. It exists only on the stack, where BRK and PHP always write a 1, while IRQ and NMI always write a 0.
The "SO" input pin, when asserted, would set the processor's overflow status bit (deasserting it does not clear the overflow bit, however). This can be used by a high-speed polling
Polling (computer science)
Polling, or polled operation, in computer science, refers to actively sampling the status of an external device by a client program as a synchronous activity. Polling is most often used in terms of input/output , and is also referred to as polled or software driven .Polling is sometimes used...
device driver, which can poll the hardware once in only three cycles by using a Branch-on-oVerflow-Clear (BVC) instruction that branches to itself; for example the Commodore 1541
Commodore 1541
The Commodore 1541 , made by Commodore International, was the best-known floppy disk drive for the Commodore 64 home computer. The 1541 was a single-sided 170 kilobyte drive for 5¼" disks...
and other Commodore
Commodore International
Commodore is the commonly used name for Commodore Business Machines , the U.S.-based home computer manufacturer and electronics manufacturer headquartered in West Chester, Pennsylvania, which also housed Commodore's corporate parent company, Commodore International Limited...
floppy disk
Floppy disk
A floppy disk is a disk storage medium composed of a disk of thin and flexible magnetic storage medium, sealed in a rectangular plastic carrier lined with fabric that removes dust particles...
drives use it to detect as quickly as possible whether the serializer
Serialization
In computer science, in the context of data storage and transmission, serialization is the process of converting a data structure or object state into a format that can be stored and "resurrected" later in the same or another computer environment...
is ready to accept or provide another byte of disk data, as a normal test-and-branch loop takes seven cycles which is too slow in that particular application. Obviously great care must be used in the device driver and the associated system design, as spurious assertion of the overflow bit could ruin arithmetic processing.
Variations and Derivatives
There were several variants of the NMOS 6502 produced:- The MOS Technology 6507MOS Technology 6507The 6507 is an 8-bit microprocessor from MOS Technology, Inc.It is essentially a 6502 chip in a smaller, cheaper 28-pin package. To do this, A15 to A13 and some other signals such as the interrupt lines are not accessible...
had reduced memory addressing capability and no interrupts. - The MOS Technology 6510MOS Technology 6510thumb|300px|Image of the internals of a [[Commodore 64]] showing the 6510 CPU . The chip on the right is the [[MOS Technology SID|6581 SID]]...
has a built-in 6-bit programmable input/output port. - The WDC 65C02WDC 65C02The Western Design Center WDC 65C02 microprocessor is an upgraded CMOS version of the popular NMOS-based MOS Technology 6502 8-bit CPU — the CMOS redesign being made by Bill Mensch of the Western Design Center...
was made in CMOSCMOSComplementary metal–oxide–semiconductor is a technology for constructing integrated circuits. CMOS technology is used in microprocessors, microcontrollers, static RAM, and other digital logic circuits...
, had more opcodes, and fixed some outstanding bugs. - The Ricoh 2A03Ricoh 2A03The Ricoh 2A03 or RP2A03 / Ricoh 2A07 or RP2A07 is the 8-bit microprocessor in the Nintendo Entertainment System video game console. It was manufactured by Ricoh...
was a 6502 variant lacking the BCD Mode, used in the Nintendo Entertainment SystemNintendo Entertainment SystemThe Nintendo Entertainment System is an 8-bit video game console that was released by Nintendo in North America during 1985, in Europe during 1986 and Australia in 1987...
.
6512
The MOS Technology 6512 was used in the BBC Micro B+64BBC Micro
The BBC Microcomputer System, or BBC Micro, was a series of microcomputers and associated peripherals designed and built by Acorn Computers for the BBC Computer Literacy Project, operated by the British Broadcasting Corporation...
, and relied on an external clock. (The 6502 used an internal clock generator to generate the
Phase 1 and Phase 2 clocks.) This was used to advantage in some designs where the clocks could be run asymmetrically, increasing overall CPU performance.
16-bit derivatives
The Western Design CenterWestern Design Center
The Western Design Center , located in Mesa, Arizona, USA, is a company developing and manufacturing MOS 65xx-based microprocessors, microcontrollers , and related support chips...
designed and produced the 65C816 processor, a 16-bit successor to the 65C02, as well as a hybrid offshoot called the 65C802 which was a 65C816 core with a 64 KB address space in a 65(C)02 pin-compatible package—it could be plugged into a 6502 board and would function as a 65C02, or it could be configured via software to expose its 16 bit accumulator
Accumulator (computing)
In a computer's central processing unit , an accumulator is a register in which intermediate arithmetic and logic results are stored. Without a register like an accumulator, it would be necessary to write the result of each calculation to main memory, perhaps only to be read right back again for...
and index registers. Few 65C802 parts were sold, and the chip is no longer produced.
The 65C816 was the core of the widely popular Super Nintendo Entertainment System
Super Nintendo Entertainment System
The Super Nintendo Entertainment System is a 16-bit video game console that was released by Nintendo in North America, Europe, Australasia , and South America between 1990 and 1993. In Japan and Southeast Asia, the system is called the , or SFC for short...
, and the Apple IIGS
Apple IIGS
The Apple , the fifth and most powerful model in the Apple II series of personal computers produced by Apple Computer. The "GS" in the name stands for Graphics and Sound, referring to its enhanced graphics and sound capabilities, both of which greatly surpassed previous models of the line...
. The 65C816 is still widely used, both as a discrete
Electronic component
An electronic component is a basic electronic element and may be available in a discrete form having two or more electrical terminals . These are intended to be connected together, usually by soldering to a printed circuit board, in order to create an electronic circuit with a particular function...
processor and as the core of a microcontroller
Microcontroller
A microcontroller is a small computer on a single integrated circuit containing a processor core, memory, and programmable input/output peripherals. Program memory in the form of NOR flash or OTP ROM is also often included on chip, as well as a typically small amount of RAM...
.
Mitsubishi
Mitsubishi
The Mitsubishi Group , Mitsubishi Group of Companies, or Mitsubishi Companies is a Japanese multinational conglomerate company that consists of a range of autonomous businesses which share the Mitsubishi brand, trademark and legacy...
(now Renesas Technology) made a line of 16-bit microcontrollers with an architecture very similar to the 65816, though it was not 100% compatible.
Synertek
Synertek
Synertek, Inc. was an American semiconductor manufacturer founded in 1973. The initial founding group consisted of Bob Schreiner , Dan Floyd, Zvi Grinfas, Jack Balletto, and Gunnar Wetlesen. The manufacturing technology was MOS/LSI...
published a data sheet and application notes on the SY6516, a 16-bit derivative of the 6502, but the part was never introduced.
Bugs and quirks
- The earliest revisions of the 6502, such as those shipped with some KIM-1KIM-1The KIM-1, short for Keyboard Input Monitor, was a small 6502-based single-board computer developed and produced by MOS Technology, Inc. and launched in 1976...
computers, had a severe bug in the RORCircular shiftIn combinatorial mathematics, a circular shift is the operation of rearranging the entries in a tuple, either by moving the final entry to the first position, while shifting all other entries to the next position, or by performing the inverse operation...
(rotate right memory or accumulator) instruction. The operation of ROR in these chips is effectively an ASL instruction that does not update the carry status bit. MOS left the instruction out of chip documentation entirely because of the defect, promising that ROR would appear on 6502 chips starting in 1976. The vast majority of 6502 chips in existence today do not exhibit this bug.
- The original 6502 and its NMOSNMOS logicN-type metal-oxide-semiconductor logic uses n-type metal-oxide-semiconductor field effect transistors to implement logic gates and other digital circuits...
derivatives are noted for having a variety of undocumented instructionsIllegal opcodeAn Illegal Opcode, also called an Undocumented Instruction, is an instruction to a CPU that is not mentioned in any official documentation released by the CPU's designer or manufacturer, which nevertheless has an effect. Illegal opcodes were common on older CPUs designed during the 1970s, such as...
, 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 arrayProgrammable logic arrayA programmable logic array is a kind of programmable logic device used to implement combinational logic circuits. The PLA has a set of programmable AND gate planes, which link to a set of programmable OR gate planes, which can then be conditionally complemented to produce an output...
) which is only defined for 151 of the 256 available opcodeOpcodeIn computer science engineering, an opcode is the portion of a machine language instruction that specifies the operation to be performed. Their specification and format are laid out in the instruction set architecture of the processor in question...
s. The remaining 105 trigger strange and hard-to-predict actions (e.g., immediately crashing the processor, performing several valid instructions at once, or simply doing nothing at all). Eastern House Software developed the "Trap65", a device that plugged between the processor and its socket to convert (trap) unimplemented opcodes into BRKBRKThe 65xx family of microprocessors, consisting of the MOS Technology 6502 and its derivatives, the WDC 65C02, WDC 65C802 and WDC 65C816, all handle interrupts in a similar fashion. There are three hardware interrupt signals common to all 65xx processors and one software interrupt, the BRK...
(software interrupt) instructions. Some programmers utilized this feature to extend the 6502's instruction set by providing functionality for the unimplemented opcodes with specially written software intercepted at the BRK instruction's 0xFFFE vector. All of the undefined opcodes have been replaced by NOPNOPIn computer science, NOP or NOOP is an assembly language instruction, sequence of programming language statements, or computer protocol command that effectively does nothing at all....
instructions in the 65C02WDC 65C02The Western Design Center WDC 65C02 microprocessor is an upgraded CMOS version of the popular NMOS-based MOS Technology 6502 8-bit CPU — the CMOS redesign being made by Bill Mensch of the Western Design Center...
CMOSCMOSComplementary metal–oxide–semiconductor is a technology for constructing integrated circuits. CMOS technology is used in microprocessors, microcontrollers, static RAM, and other digital logic circuits...
version, although with varying byte sizes and execution times. In the 65C816, all 256 opcodes perform defined operations.
- The 6502's memory indirect jumpIndirect branchAn indirect branch is a type of program control instruction present in some machine language instruction sets. Rather than specifying the address of the next instruction to execute, as in a direct branch, the argument specifies where the address is located...
instruction, JMP (), is partially broken. If is hexHexadecimalIn mathematics and computer science, hexadecimal is a positional numeral system with a radix, or base, of 16. It uses sixteen distinct symbols, most often the symbols 0–9 to represent values zero to nine, and A, B, C, D, E, F to represent values ten to fifteen...
xxFF (i.e., any word ending in FF), the processor will not jump to the address stored in xxFF and xxFF+1 as expected, but rather the one defined by xxFF and xx00. This defect continued through the entire NMOS line, but was corrected in the CMOS derivatives.
- The NMOS 6502's indexed addressing across page boundaries will do an extra read of invalid address. This can cause issues by accessing hardware that acts on a read (e.g., clearing timer or IRQ flags, sending an I/O handshake, etc.). This defect continued through the entire NMOS line, but was fixed in the CMOS derivatives, in which the processor does an extra read of the last instruction byte.
- The 6502's read/modify/write instructions perform one read and two write cycles. This characteristic may cause issues by twice accessing hardware that acts on a write. This anomaly continued through the entire NMOS line, but was fixed in the CMOS derivatives, in which the processor will do two reads and one write cycle. Good programming practice will generally avoid executing read/modify/write instructions on hardware registers.
- The N (result negative), V (sign bit overflow) and Z (result zero) status flagsStatus registerA status register or flag register is a collection of flag bits for a processor. An example is the FLAGS register of the x86 architecture....
are not valid when performing arithmetic operations while the processor is in BCDBinary-coded decimalIn computing and electronic systems, binary-coded decimal is a digital encoding method for numbers using decimal notation, with each decimal digit represented by its own binary sequence. In BCD, a numeral is usually represented by four bits which, in general, represent the decimal range 0 through 9...
mode, as these flags reflect the binary, not BCD, result. This limitation was removed in the CMOS derivatives. Therefore, this feature may be used to cleanly distinguish CMOS from NMOS CPU versions without using any illegal opcodes.
- If the processor happens to be in BCD mode when a hardware interrupt occurs it will not revert to binary mode. This quirk could result in hard-to-solve bugs in the interrupt service routine if it fails to clear BCD mode before performing any arithmetic operations. For example, the Commodore 64Commodore 64The Commodore 64 is an 8-bit home computer introduced by Commodore International in January 1982.Volume production started in the spring of 1982, with machines being released on to the market in August at a price of US$595...
's kernel did not correctly handle this processor characteristic, requiring that IRQs be disabled or revectored during BCD math operations. This issue was addressed in the CMOS derivatives as well.
- The 6502 instruction set includes BRK (opcode $00), which is technically a software interrupt (similar in spirit to the SWI mnemonic of the 6800Motorola 6800The 6800 was an 8-bit microprocessor designed and first manufactured by Motorola in 1974. The MC6800 microprocessor was part of the M6800 Microcomputer System that also included serial and parallel interface ICs, RAM, ROM and other support chips...
and ARMARM architectureARM is a 32-bit reduced instruction set computer instruction set architecture developed by ARM Holdings. It was named the Advanced RISC Machine, and before that, the Acorn RISC Machine. The ARM architecture is the most widely used 32-bit ISA in numbers produced...
processors). BRK is most often used to interrupt program execution and start a machine code monitorMachine code monitorA machine code monitor is software built into or separately available for various computers, allowing the user to enter commands to view and change memory locations on the machine, with options to load and save memory contents from/to secondary storage.Machine code monitors became something of a...
for testing and debugging during software development. It could also be used to route program execution using a simple jump table (analogous to the manner in which the 8088Intel 8088The Intel 8088 microprocessor was a variant of the Intel 8086 and was introduced on July 1, 1979. It had an 8-bit external data bus instead of the 16-bit bus of the 8086. The 16-bit registers and the one megabyte address range were unchanged, however...
and derivatives handle software interrupts by number). Unfortunately, if a hardware interrupt occurs at the same time the processor is fetching a BRK instruction, the NMOS version of the processor will fail to execute BRK and instead proceed as if only a hardware interrupt had occurred. This fault was corrected in the CMOS implementation of the processor.
- When executing JSR (jump to subroutine) and RTS (return from subroutine) instructions, the return address pushed to the stack by JSR is that of the last byte of the JSR operand (that is, the most significant byte of the subroutine address), rather than the address of the following instruction. This is because the actual copy (from program counterProgram counterThe program counter , commonly called the instruction pointer in Intel x86 microprocessors, and sometimes called the instruction address register, or just part of the instruction sequencer in some computers, is a processor register that indicates where the computer is in its instruction sequence...
to stackStack (data structure)In computer science, a stack is a last in, first out abstract data type and linear data structure. A stack can have any abstract data type as an element, but is characterized by only three fundamental operations: push, pop and stack top. The push operation adds a new item to the top of the stack,...
and then vice-versa) takes place before the automatic increment of the program counter that occurs at the end of every instruction. This characteristic would go unnoticed unless you pulled the return address to pick up parameters in the code stream (a common 6502 programming idiom). It remains a characteristic of 6502 derivatives to this day.
Acceleration
Many users of 1 MHz 6502-based systems soon wished their computers could go faster. As the 6502 is externally-clocked, upgrading the speed involved more than dropping a faster chip into the processor socket; many other components would also need to be modified. To meet user demand, a number of companies sold hardware to speed up those systems. These "accelerators" included a modicum of high-speed RAM and glue circuitry used to synchronize the faster processor with the computer's original RAM and its peripherals. For example, the Apple II floppy disk relied on software accessing the controller's I/O registers with critical timing; Apple II accelerators were therefore designed to fall back to 1 MHz during disk access. The first accelerators were circuit boards; some later accelerators (such as the Zip Chip) miniaturized the processor and support circuits to fit into a DIP package that was plug-compatible with the original processor.6502 in popular culture
In the science fiction movie The TerminatorThe Terminator
The Terminator is a 1984 science fiction action film directed by James Cameron, co-written by Cameron and William Wisher Jr., and starring Arnold Schwarzenegger, Michael Biehn, and Linda Hamilton. The film was produced by Hemdale Film Corporation and distributed by Orion Pictures, and filmed in Los...
(1984), starring Arnold Schwarzenegger
Arnold Schwarzenegger
Arnold Alois Schwarzenegger is an Austrian-American former professional bodybuilder, actor, businessman, investor, and politician. Schwarzenegger served as the 38th Governor of California from 2003 until 2011....
, the audience at one point is treated to a view through the T-800
T-800
"The Terminator" refers to a number of fictional characters portrayed by Arnold Schwarzenegger – a cyborg, initially portrayed as a programmable assassin and military infiltration unit...
Model-101 robot character's eye/camera
Computer vision
Computer vision is a field that includes methods for acquiring, processing, analysing, and understanding images and, in general, high-dimensional data from the real world in order to produce numerical or symbolic information, e.g., in the forms of decisions...
display with some 6502 assembly
Assembly language
An assembly language is a low-level programming language for computers, microprocessors, microcontrollers, and other programmable devices. It implements a symbolic representation of the machine codes and other constants needed to program a given CPU architecture...
/machine code
Machine code
Machine code or machine language is a system of impartible instructions executed directly by a computer's central processing unit. Each instruction performs a very specific task, typically either an operation on a unit of data Machine code or machine language is a system of impartible instructions...
program fragments scrolling
Scrolling
In computer graphics, filmmaking, television production, and other kinetic displays, scrolling is sliding text, images or video across a monitor or display. "Scrolling", as such, does not change the layout of the text or pictures, or but incrementally moves the user's view across what is...
down the screen. The program was listing the Apple DOS
Apple DOS
Apple DOS refers to operating systems for the Apple II series of microcomputers from late 1978 through early 1983. Apple DOS had three major releases: DOS 3.1, DOS 3.2, and DOS 3.3; each one of these three releases was followed by a second, minor "bug-fix" release, but only in the case of Apple DOS...
3.3 disassembled
Disassembler
A disassembler is a computer program that translates machine language into assembly language—the inverse operation to that of an assembler. A disassembler differs from a decompiler, which targets a high-level language rather than an assembly language...
program listing. Also shown is the output from a run of an Apple
Apple II series
The Apple II series is a set of 8-bit home computers, one of the first highly successful mass-produced microcomputer products, designed primarily by Steve Wozniak, manufactured by Apple Computer and introduced in 1977 with the original Apple II...
checksum
Checksum
A checksum or hash sum is a fixed-size datum computed from an arbitrary block of digital data for the purpose of detecting accidental errors that may have been introduced during its transmission or storage. The integrity of the data can be checked at any later time by recomputing the checksum and...
program called KEY PERFECT 4.0, published in Nibble magazine
Nibble (magazine)
Nibble was a magazine for Apple II computer users with a focus on hobbyist programming. The name meant "half a byte" or "four bits." Its slogan was "The Magazine for Apple II Enthusiasts." Most of the articles incorporated the source code of a small to medium-sized utility, application program,...
.
Bender, a fictional android "industrial robot
Industrial robot
An industrial robot is defined by ISO as an automatically controlled, reprogrammable, multipurpose manipulator programmable in three or more axes...
" manufactured in 2998, and a main character in the animated TV series Futurama
Futurama
Futurama is an American animated science fiction sitcom created by Matt Groening and developed by Groening and David X. Cohen for the Fox Broadcasting Company. The series follows the adventures of a late 20th-century New York City pizza delivery boy, Philip J...
created by Matt Groening
Matt Groening
Matthew Abram "Matt" Groening is an American cartoonist, screenwriter, and producer. He is the creator of the comic strip Life in Hell as well as two successful television series, The Simpsons and Futurama....
, was revealed to have a 6502 as his "brain" in the episode "Fry and the Slurm Factory
Fry and the Slurm Factory
"Fry and the Slurm Factory" is the thirteenth episode of the first production season of Futurama. It originally aired in North America on November 14, 1999 as the fourth episode of the second broadcast season. The episode was directed by Ron Hughart and written by Lewis Morton...
". David X. Cohen
David X. Cohen
David Samuel Cohen , primarily known as David X. Cohen, is an American television writer. He has written for The Simpsons and he is the head writer and executive producer of Futurama.-Early life:...
(the head writer and executive producer of Futurama
Futurama
Futurama is an American animated science fiction sitcom created by Matt Groening and developed by Groening and David X. Cohen for the Fox Broadcasting Company. The series follows the adventures of a late 20th-century New York City pizza delivery boy, Philip J...
) has claimed in an interview with IEEE Spectrum
IEEE Spectrum
IEEE Spectrum is a magazine edited by the Institute of Electrical and Electronics Engineers. The IEEE's description of it is:IEEE Spectrum began publishing in January 1964 as a successor to Electrical Engineering...
that he and friends David Borden and David Schiminovich wrote an assembly language
Assembly language
An assembly language is a low-level programming language for computers, microprocessors, microcontrollers, and other programmable devices. It implements a symbolic representation of the machine codes and other constants needed to program a given CPU architecture...
compiler
Compiler
A compiler is a computer program that transforms source code written in a programming language into another computer language...
(for a custom language they created named "FLEET") for the Apple II Plus
Apple II Plus
The Apple II Plus was the second model of the Apple II series of personal computers produced by Apple Computer, Inc. It was sold new from June 1979 to December 1982.-Features:...
, which uses the 6502, while at high school, and confirmed that this led him to include the reference in the show.
See also
- Lisa assemblerLisa assemblerLazer's Interactive Symbolic Assembler is an interactive MOS 6502 assembler for Apple II computers written by Randall Hyde in the late 1970s.The latest version of Lisa is V3.2. Syntax mistakes can be reported immediately in the edit mode...
- MOS Technology 6502-based home computers
- Interrupts in 65xx processors
- VasmVasmvasm is a free assembler supporting various CPUs and many different output formats.CPUs officially supported by vasm include M680x0 family, ColdFire family, 80x86 family, PowerPC, ARM family, Z80 family, C16x/ST10, 6502 etc. Vasm supports Standard MIT , Motorola/Freescale 68k and Old 8-bit style...
, a free assembler
External links
General information:- 6502.org - the 6502 microprocessor resource – Repository and portal (Mike Naberezny)
- 650x information – Concise description, photos of MOS and second source chips; at cpu-collection.de (Dirk Oppelt)
- a2DMAMagic – The secret, transparent, high-throughput 6502 DMA channel (by Jorge Chamorro Bieling)
- mdfs.net – 6502 instruction set
Instruction set features:
- 6502 - the first RISC µP – With link to concise 6502 programming chart in PDFPortable Document FormatPortable Document Format is an open standard for document exchange. This file format, created by Adobe Systems in 1993, is used for representing documents in a manner independent of application software, hardware, and operating systems....
(Eric Clever)
Emulators and simulators:
- Visual Transistor-level Simulation of the 6502 CPU
- List of 6502 software emulators – At Zophar's Domain (Sam Michaels)
- 6502 simulator for Windows – At Dan Boris' homepage hosted by The Atari Gaming Headquarters
- Web-based 6502 compatible compiler and emulator written in JavaScript – by Stian Søreng
Early 6502 computers:
- Apple I Owners Club – Hosted by the Applefritter site (Tom Owad)
- KIM-1 schematics – At The Obsolete Technology Website (anonymous collector)
- Rockwell AIM 65 – The Old Computer Hut
Hardware accelerators:
- 6502 accelerator information – At the Apple II History website (Steven Weyhrich)
- "Underneath the Hood of the SuperCPU" – By Jim Brain, in C=Hacking, Issue #12, Version 1.3, March 1996 (search for "@(#)cmdcpu")
Hardware:
- The Western Design Center, Inc. (WDC) – home of the 65xx brand CMOS microprocessors.