hundred rabbits logo consisting of one hundred white dots

6502 assembly

introduction

The assembly language is a low-level processor centric programming language. We focus our interest on the human-readable 6502 processor and assembly, as opposed to x86 assembly language which is much less intelligible. This guide is meant to collect our resources to help you write projects for the classic Nintendo Entertainment System.

This is the language we used to create Donsol.

cookbook

We have assembled a collection of example projects to help you better understand the ecosystem, and we have created a spritesheet and nametable editor called Nasu.

basics

registers

The 6502 handles data in its registers, each of which holds one byte(8-bits) of data. There are a total of three general use and two special purpose registers:

architecture

directives

Directives are commands you send to the assembler to do things like locating code in memory. They start with . and are indented. This sample directive tells the assembler to put the code starting at memory location $8000, which is inside the game ROM area.

The label is aligned to the far left and has a : at the end. The label is just something you use to organize your code and make it easier to read. The assembler translates the label into an address.

The opcode is the instruction that the processor will run, and is indented like the directives.

The operands are additional information for the opcode. Opcodes have between one and three operands.

Comments are to help you understand in English what the code is doing. When you write code and come back later, the comments will save you. You do not need a comment on every line, but should have enough to explain what is happening. Comments start with a ; and are completely ignored by the assembler. They can be put anywhere horizontally, but are usually spaced beyond the long lines.

  .org $8000  ; directive
MyFunction:        ; label
LDA #$FF         ; opcodes operands
JMP MyFunction