What's a 6502?

The 6502 processor was used in a lot of gaming console during the 80’s, including the NES, Apple II, Commodore 64 (who later bought the company that made the 6502!), multiple Atari machines, and tons more. It’s instruction set is known as 6502 Assembly, or just 6502.

Why do I want to learn it?

Why not? It’s a fun language that can be ported to many different systems! It’s heavily used in the NES development community, which actively make NES games for emulators and consoles. Something like x86 may be used more today, but there’s no real reason why you wouldn’t use a language that compiles into x86. Until someone create a language that compiles to 6502, we’ll all be stuck here coding it.

Tutorial

Let’s dive on in! We’ll be using a simulator made by skilldrick in Javascript. You can find more info on the simulator page.

Not like any OOP, now is it? 6502 uses a variety of instructions to get it’s job done, each of which may contain an argument.

The first instruction is lda, or LoaD to register A, and it’s argument is the number you want loaded. There are three registers on the 6502, A, X, and Y, which temporarily store information. Using lda, we can load whatever number we want onto the A register.

Numbers can have two different meanings. If they have a # before it, they are the number itself. If not, it’s redirected to the location in memory of that number. A $ before a number means it’s in hexadecimal, or base 16. So, the #$01 means that lda is going to load 1 into register A (as you can see by the A= changing to the number 01 in the Debug menu).

Data stored between $200 and $5ff will be displayed on the screen to the right. The color will depend on the value stored.

The second instruction is sta, or STore what's on A. This will take the number on register A and store it at the provided memory location. So, sta $020: store the 1 that is on A in $020.

Loading to other registers

Using one register for everything can be difficult, so they added two more! X and Y are the other two registers, and they’re as easy to use as A!

Instead of a in lda, we’re using ldx to load to register X. The same goes for stx. txa transfers the value in X to A. inx increments the value in X by 1.