The NES is a beautifully complex piece of 8 bit machinery. It uses a customised Motorola 6502 processor which is more similar to the x86 chips than the ARM series. For its Picture Processing needs, the NES has a PPU (a Picture Processing Unit) chip that we program indirectly through memory registers.
NES Assembly Language\
There are three CPU memory registers that we are primarily concerned with, these are:
- The A register, this is the Accumulator, this processes all math operations.
- The X register, used for indexing memory addressings
- The Y register, this is also used for indexing memory addresses
All three registers can be loaded with numbers of values from memory. The uses listed above are their special functions. There are a few others but for the moment I want to keep things simple.
The first instruction we will learn is the LD set. After the keyword LD we place one of the 3 registers mentioned above. Here’s some sample code to illustrate this
Note that these are 8-bit registers. You may be wondering what the #$ means. The # symbol means immediate value, as the number is just a numerical value and not an address in memory to load from. The $ symbol means that the number is in hexadecimal. If the $ was a % then the number would be taken as a decimal number. Some examples of this are:
Memory Address Addressing
For a number to be interpreted as a memory address by the assembler, all that needs to be done is to leave off the #. Now also keep in mind that addresses are usually represented as 16-bit hex numbers, so to load a register with a value from memory, we would do this:
Storing Values in Memory
The next instruction we will learn is the ST family, after the ST instruction we would place one of the three registers. This is the store instruction and does not take an immediate value as an operand. Some examples are:
This is termed as direct addressing where we give the actual address we want to put something into. The addresses are usually represented as hex numbers, if you use a 2 digit number in a store instruction, it is interpreted as 00xx where xx is the 2 digit number you used.