Introduction To The 6502

This tutorial is a general introduction to the 6502. If you have read Hold That Thought, and you're still with us, welcome to the world of 6502 programming


The 6502 microprocessor is a computer. All computers are simply overgrown calculators. They do calculations that we humans are too lazy to do, and they do it faster than we can. Much faster. It's interesting to note here that the first electronic computer ENIAC, was built to help the US Army figure out how to shoot better. It did this by helping create ballistics data —- by calculating it.

The 6502 Monster

So, the 6502 is nothing more than a calculator. Let me restate that. It is an overgrown calculator with a bunch of boxes and hands. It picks things up from the boxes, chews them up (calculates them), and puts them back down. Sometimes, it just moves things around. Have that picture in your mind? If not take a minute to imagine it. Once you got it, continue reading.

The mouth of the 6502 is the accumulator. It is the only part of the 6502 that can chew things up (crunch numbers). Even though it can pick up things with it's mouth, it has two hands, named X and Y. They can pick up stuff too. If the 6502 wants, it can perform a juggling act between it's mouth and both it's hands.

It also has 64000+ (little) boxes. It picks things up from the boxes. It crunches them. Sometimes, it take a look at them to see what to do next. The entire 6502's life is spent looking at these boxes. What's more, other things use these boxes too. They put things in the boxes, they take things out.

When the 6502 wants to "talk" to the "outside world", it puts a message in one (or more) of these tiny little boxes. Then, it's intended receiver picks it up. If an outside agent wants to talk to the 6502, it puts a message in one of the boxes and the 6502 picks it up. Both the 6502 monster and the outside agents know which boxes to put things into and take things out of because they are assigned. The 6502 knows that if it picks up something from a specific box, it's coming from the agent assigned to that box.

Strange world isn't it? Welcome to 6502 game programming. You will be able to make sense of the 6502 monster shortly.

Programming the 6502

Fortunately, the 6502 is a stupid beast and can be programmed. Think about the description above and see if you can think how you program the 6502. Got it?

That's right. You simply put things in it's boxes. The 6502 starts at one of the boxes, finds an instruction, picks it up, and then does what it says. Then, it moves on to the next instruction.

The Boxes

The 64000+ boxes are actually make up the memory locations of the 6502. That's about 64k. Each memory location can hold a number between 0 and 255. The 6502 is able to tell the difference between a number and instruction because it knows what to expect. For example, if it is looking for an instruction, the 6502 will interpret that number as an instruction.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution 2.5 License.