Skip to main content

Questions tagged [6502]

For 6502 series of processors, including hardware and assembly language questions. Use with [hardware] for the hardware interface in particular.

Filter by
Sorted by
Tagged with
94 votes
7 answers
29k views

Why would a NES game use an undocumented 1-byte or 2-byte NOP in production?

Reading the NESdev wiki page on CPU unofficial opcodes, I see a few games use an undocumented 2-byte NOP instuction in production: Puzznic, F-117A Stealth Fighter, and Infiltrator use $89 #i. Beauty ...
JAL's user avatar
  • 9,620
58 votes
8 answers
14k views

Could you reverse engineer silicon just by looking at it?

I was interested in a recent interview of Masayuki Uemura, one of the engineers who designed the Nintendo Famicom in the early 80s. During initial design phase of the Famicom, one of the first things ...
da66en's user avatar
  • 699
56 votes
13 answers
10k views

What languages are better fit for generating efficient code for 8-bit CPU's than C?

I found Why do C to Z80 compilers produce poor code? very interesting as it pointed out that C (which was leveraged to be an abstraction of a CPU for porting Unix) was not a very easy language to ...
Thorbjørn Ravn Andersen's user avatar
47 votes
6 answers
13k views

Why does the 6502 have the BIT instruction?

The 6502 has a bit instruction which copies two of the bits into the N and V flags, pretends to and the byte with the accumulator, but discards the result and only affects Z. I'm having a hard time ...
Omar and Lorraine's user avatar
47 votes
3 answers
6k views

What happened to the SEV instruction on the 6502?

The 6502 has a group of opcodes which copy bit 5 from the opcode into one of the status flags. (I know it's not implemented this way, but it looks as though the bit fields are: 2 bits to select the ...
Omar and Lorraine's user avatar
42 votes
5 answers
7k views

Why did so many early microcomputers use the MOS 6502 and variants?

Quite a few successful early microcomputers used the MOS 6502 CPU. This included, but was not limited to, systems like the Apple I, Apple II, Commodore PET, and Ataris. A followup known as the MOS ...
user's user avatar
  • 5,336
40 votes
7 answers
28k views

Comparing raw performance of the Z80 and the 6502

A lot has been said on the internet about the 6502, at 1MHz, being roughly equivalent in performance to the Z80, at 4 MHz. It is said the Z80 has a typical 4 clock ticks per instruction, while the ...
Biff Iam's user avatar
  • 2,229
35 votes
2 answers
3k views

Can the two CPUs in a Commodore 128 run at the same time?

The Commodore 128 has two CPUs. One is some variant of the 6502, and the other is a Z80. One CPU is there for compatibility with the Commodore 64 and the other is there presumably to give basic ...
Omar and Lorraine's user avatar
33 votes
2 answers
4k views

What is the relative code density of 8-bit microprocessors?

When RAM is at a premium, as it was in the old days, a greater code density of an instruction set can be a substantial advantage. (Click saver: Code density refers loosely to how many microprocessor ...
Leo B.'s user avatar
  • 19.4k
32 votes
3 answers
4k views

How did Elite do vertex transformation?

In 3D graphics, vertex transformation is the process of converting x,y,z coordinates in 3D space, to x,y coordinates on the screen. According to https://www.khronos.org/opengl/wiki/...
rwallace's user avatar
  • 63.1k
31 votes
2 answers
5k views

Why did Sinclair choose the Z80 for its range of home computers?

The Sinclair computers are known for their low cost compared with other computers that were popular in the early 1980s. This is why they had membrane keyboards, or that rubber stuff in the case of the ...
Omar and Lorraine's user avatar
31 votes
3 answers
7k views

Why didn't the 6502 have increment/decrement opcodes for A?

In 6502 Assembly, we can use INX and INY to increase the value stored in X and Y. They can be decreased with DEX and DEY. However, it seems that there are no such instructions for A, like INA or DEA. ...
LuNa's user avatar
  • 588
29 votes
3 answers
7k views

What are uses of the byte after BRK instruction on 6502?

The BRK instruction on the MOS 6502 seems to be one of the more ill-documented features of the processor. The 1976 preliminary data sheet from MOS indicates that it's a 1-byte instruction using the &...
cjs's user avatar
  • 26.8k
29 votes
2 answers
3k views

Why does 6502 indexed LDA take an extra cycle at page boundaries?

On the 6502 CPU, this instruction: LDA $0380,Y takes either 4 or 5 cycles, depending on whether the indexing crosses a page boundary. But this instruction: STA $0380,Y takes 5 cycles regardless ...
fadden's user avatar
  • 9,070
27 votes
7 answers
7k views

Did anyone ever run out of stack space on the 6502?

Unlike its main rival the Z80, the 6502 had a size limit of 256 bytes for the hardware stack. That sounds like a very tight limit, but in my experience, it was never actually an issue; by the time you ...
rwallace's user avatar
  • 63.1k
26 votes
6 answers
10k views

Why are old CPUs like MOS Technology 6502 and Motorola 68000 considered better for real time systems applications than modern x86 based CPUs?

Reading the Wikipedia article about real-time computing, I found written that: Once when the MOS Technology 6502 (used in the Commodore 64 and Apple II), and later when the Motorola 68000 (used in ...
bobeff's user avatar
  • 563
25 votes
2 answers
4k views

Was leaving all xxxxxx11 opcodes unused on the 6502 a deliberate design choice?

The 6502, like many 8-bit processors, has a somewhat arcane opcode-mode restrictions. On most such processors, the restriction is a clear result of trying to pack a lot of instructions into a limited ...
supercat's user avatar
  • 37.5k
24 votes
4 answers
4k views

Why are branches relative in many 8-bit CPUs?

I was looking over an old article on the 6809 and was perusing the opcodes and noticed that the branch instructions came in two flavors, long and short. That sparked a memory about one of the 6502-...
Maury Markowitz's user avatar
24 votes
4 answers
2k views

Was the design of MS-BASIC for 6502 based on MS-BASIC for 8080?

Looking through the source code of the 6502 MS-BASIC, certain parts of it seem more reminiscent of how things would be done on the 8080 than on how they should be done on the 6502. Code to find a ...
supercat's user avatar
  • 37.5k
24 votes
1 answer
2k views

How good was Woz's FP code?

I just came across this amazing 1976 article by Woz. In it he describes a relatively complete floating-point system for the 6502 with a 32-bit format (similar to earlier MS code). I understand the ...
Maury Markowitz's user avatar
22 votes
7 answers
5k views

Why were there no 32-bit versions of 65xx CPUs, or 64-bit versions of m68k CPUs?

I don't understand why Western Design Center made the 65816 a 16-bit upgrade to the 6502 but Commodore Semiconductor Group/MOS Technology didn't make their own variant & why neither company made ...
6502Assembly4NESgames's user avatar
22 votes
3 answers
12k views

Where to buy a 6502 chip

I want to purchase a 6502 40 pin CPU in order to verify if my 6502 is faulty, I've seen I can buy from Hong Kong but would prefer closer (to the UK), RS and CPC don’t seen to have any. Most answers ...
Bigmalc40's user avatar
  • 337
21 votes
3 answers
7k views

How much did the 6502 and Z80 cost?

It is said that the 6502 was cheaper than the Z80. As of 1978, what were the actual prices of the two chips, in wholesale quantity?
rwallace's user avatar
  • 63.1k
21 votes
3 answers
7k views

6510 clock rate of C64: Why was it considerably slower than the 6502 of the Atari 800?

According to Wikipedia, the Atari 8 bit series had a 6502 running at ~1.8 MHz. Why was the clock speed of the 6510 for the C64, which was designed a couple of years later, considerable slower? Was the ...
Marco's user avatar
  • 1,397
21 votes
1 answer
2k views

Why did the 6502 handle BCD with a special mode?

The 6502 had special support for BCD arithmetic, because it was widely used in those days; this much, it had in common with other CPUs. But the 8080 and 6800 implemented this in the form of a 'decimal ...
rwallace's user avatar
  • 63.1k
19 votes
3 answers
5k views

What is the purpose of mirrored memory regions in NES's CPU memory map? [duplicate]

[Please see answers to this related question as well] I've started reading the "official" NES Documentation and in page ten, it says that "memory locations $0000-$07FF are mirrored ...
anmomu92's user avatar
  • 193
19 votes
4 answers
4k views

How did integer multiplication work in 8-bit BASIC without CPU support

I've recently been teaching my 11 year old binary multiplication, which is on the UK maths syllabus at secondary school. We have used long multiplication, eg shift and add. This has made me wonder ...
Mark Williams's user avatar
19 votes
1 answer
4k views

How did the 6502 ALU perform a decrement?

Assuming that this diagram is correct: Instructions like INC, INX, and INY can easily perform increment using ALU sum with data on B input, 0 on A input and carry_in set. But how do instructions like ...
Johnmph's user avatar
  • 389
19 votes
2 answers
2k views

Is it possible to procedurally determine the number of cycles a particular instruction takes on a 6502?

Most emulators store the number of cycles a particular instruction takes in an array, and then adds any conditional cycles if needed (when crossing page boundaries, for example). I'm wondering if ...
w.brian's user avatar
  • 393
18 votes
5 answers
4k views

Why are different emulators needed to run platforms that use 6502 assembly code?

To my knowledge, an emulator turns machine code for a console into something that your computer can understand. For example, assembly code from a Gamecube game is not the same as from a .exe file. ...
Jonathan O'Brady's user avatar
18 votes
6 answers
7k views

How slow was the 6502 BASIC compared to Assembly

Imagine a modern computer, where let's say Python is a high level programming language and needs to be interpreted in order to execute a piece of code. You could write some code in C, compile it, ...
Bartek Malysz's user avatar
18 votes
2 answers
6k views

What does "jmp *" mean in 6502 assembly?

Right now I am learning 6502 assembly. Currently I am using the MADS assembler to program for the Atari 800. This program is just a small tutorial program that came with the assembler zip file I ...
user115898's user avatar
18 votes
2 answers
4k views

Did the NES CPU save die area by omitting BCD?

The NES CPU was a copy of the 6502 with the BCD circuitry removed. As I understand it, this modification was motivated by a theory that BCD was the only part of the 6502 that was actually patented, so ...
rwallace's user avatar
  • 63.1k
18 votes
2 answers
4k views

Why does the 6502 JSR instruction only increment the return address by 2 bytes?

Currently messing with 6502 assembly on a C64, and I don't understand why the JSR instruction is so weird. According to the instruction table, JSR is a 3-byte instruction and only operates in absolute ...
Jeroen Jacobs's user avatar
18 votes
3 answers
1k views

Did any micros use the 6502 BCD mode in their OS?

I know the Atari's FP package used BCD for rather dubious reasons, but does anyone know of other examples of basic "operating system" level code on common platforms that used BCD? I suspect BCD was ...
Maury Markowitz's user avatar
17 votes
3 answers
2k views

For how long can you safely stop the clock on an NMOS 6502?

As with most NMOS processors, the NMOS versions of the 6502 (and even earlier CMOS versions) do not have a static core. Thus, if you run the clock too slowly or stop the clock for too long while doing ...
cjs's user avatar
  • 26.8k
17 votes
1 answer
3k views

Why was the 6502 version of Microsoft BASIC coded like the 8080 and 6800 versions even though this was rather inefficient?

It's quite clear that the 6502 version of Microsoft BASIC at all levels uses substantially the same structure and technique as the earlier 8080 and 6800 versions. As has been pointed out in various ...
cjs's user avatar
  • 26.8k
17 votes
1 answer
1k views

Why is the Apple II hi-res HGR command so slow?

The Apple II hi-res screen sits on 8KB of memory, so it should be possible to erase it quickly. The Applesoft HGR command is slow enough that the "Venetian blind" erasure is clearly visible. ...
fadden's user avatar
  • 9,070
17 votes
2 answers
2k views

How did the Trap65 work?

The Wikipedia page on the MOS 6502 mentions a hardware device called the Trap65 which apparently sat between the 6502 and its socket to trap any undocumented opcodes. The wiki page has the usual ...
Omar and Lorraine's user avatar
17 votes
4 answers
2k views

Best way to locate data on ROM? (6502 Processor)

Lately I've been interested in how old machines work, in particular an NES. While there are quite a few resources on the basic operations and even some games that have been totally broken down byte by ...
Aquova's user avatar
  • 173
16 votes
4 answers
3k views

PDP-8 transistor count

https://en.wikipedia.org/wiki/Transistor_count provides some transistor count figures for early microprocessors, e.g. 8008 and 6502 both listed at around 3500. The PDP-8 was a 12-bit computer with a ...
rwallace's user avatar
  • 63.1k
16 votes
3 answers
3k views

Can the 6502 clock be changed on the fly?

I was wondering if the original NMOS 6502 has any timing limitations on changing the clock rate during operation? I ask, because the CSG 8502 version could "run at double the clock rate of the ...
Maury Markowitz's user avatar
16 votes
1 answer
2k views

How did the 6502 CPU get its name?

I am interested in the etymology of the name for the 6502 CPU. How were those numbers arrived at by the designers? Do they refer to anything specific? Is there some sort of origin story? I found some ...
lookaside's user avatar
  • 501
16 votes
2 answers
1k views

What is this code on the zero page that was put there by the BASIC ROM?

(question copied from SO (from the days before RC.SE existed): http://stackoverflow.com/q/31877835/477476) Zero-page memory maps of the PET that I've found claim that the zero page address range$00C2....
Cactus's user avatar
  • 2,760
16 votes
1 answer
2k views

Why did the Apple IIe use a 2 MHz-rated 6502, even though it ran at only 1 MHz?

The Apple IIe was designed to be timing-compatible with the Apple II+ so that timing-depndent software (such games and copy-protection systems) and hardware designed for the Apple II and II+ would, ...
cjs's user avatar
  • 26.8k
16 votes
2 answers
2k views

6502 branch offset calculation

This question expands on How does the 6502 implement its branch instructions? I'm working on a cycle accurate VHDL implementation on an FPGA. I have much of the program logic already written, but I ...
Evan's user avatar
  • 163
15 votes
7 answers
2k views

New 6502 BASICs?

I sort of "have a thing for BASIC" right now, which has led to a couple of great exchanges here in RSE about the variations "back in the day". I'm wondering if anyone is aware of other modern BASICs ...
Maury Markowitz's user avatar
15 votes
2 answers
1k views

Why is the addressing mode for BRK defined as "stack" in the W65C02S datasheet?

I most online documentation, I find the addressing mode for BRK to be "implied", which is logical. In the W65C02S datasheet however, it is set as "stack": Is there some reasoning ...
Bart Friederichs's user avatar
15 votes
2 answers
2k views

How could high level functions with return values map to 6502 assembly? (if at all possible)

What sort of code could be used to substitute a high level function with a return value to a 6502 subroutine? Take this C-like function for example. byte func(byte a, byte b, byte c) { d = (a + b)...
Accumulator's user avatar
15 votes
2 answers
686 views

Why did Acorn use the 6502?

It is an interesting quirk of the British microcomputer industry, that the main vendor of cheap microcomputers, Sinclair, used the better, more expensive CPU (Z80), whereas the main vendor of better, ...
rwallace's user avatar
  • 63.1k