1 Overview
| Name | Info | Addressing modes | Affected flags | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| No memory | Relative | Absolute | Page 0 | Indirect | ||||||||||||
| NI | I | NI | I | NI | I | N | V | D | I | Z | C | |||||
| arthmetic | ADC |
Add with carry | Immediate | โ | โ | โ | โ | โ | โ | โ | โ | โ | ||||
SBC |
Subtract with carry | Immediate | โ | โ | โ | โ | โ | โ | โ | โ | โ | |||||
INC |
Increment | โ | โ | โ | โ | โ | โ | |||||||||
DEC |
Decrement | โ | โ | โ | โ | โ | โ | |||||||||
| conditional | BIT |
Bit compare with A | โ | โ | โ | โ | โ | |||||||||
CMP |
Compare with A | Immediate | โ | โ | โ | โ | โ | โ | โ | โ | ||||||
CPX |
Compare with X | Immediate | โ | โ | โ | โ | โ | |||||||||
CPY |
Compare with Y | Immediate | โ | โ | โ | โ | โ | |||||||||
| storage | LDA |
Load in A | Immediate | โ | โ | โ | โ | โ | โ | โ | ||||||
LDX |
Load in X | Immediate | โ | โ | โ | โ | โ | โ | ||||||||
LDY |
Load in Y | Immediate | โ | โ | โ | โ | โ | โ | ||||||||
STA |
Store in A | โ | โ | โ | โ | โ | ||||||||||
STX |
Store in X | โ | โ | โ | ||||||||||||
STY |
Store in Y | โ | โ | โ | ||||||||||||
| bit arthmetic | AND |
And | Immediate | โ | โ | โ | โ | โ | โ | โ | ||||||
EOR |
Exclusive or | Immediate | โ | โ | โ | โ | โ | โ | โ | |||||||
ORA |
Inclusive or | Immediate | โ | โ | โ | โ | โ | โ | โ | |||||||
LSR |
Shift bits right | Accumulator | โ | โ | โ | โ | โ | โ | โ | |||||||
ASL |
Shift bits left | Accumulator | โ | โ | โ | โ | โ | โ | โ | |||||||
ROL |
Rotate bits left | Accumulator | โ | โ | โ | โ | โ | โ | โ | |||||||
ROR |
Rotate bits right | Accumulator | โ | โ | โ | โ | โ | โ | โ | |||||||
| branching | BPL |
Branch if N not set | โ | |||||||||||||
BMI |
Branch if N set | โ | ||||||||||||||
BVC |
Branch if V not set | โ | ||||||||||||||
BCC |
Branch if C not set | โ | ||||||||||||||
BCS |
Branch if C set | โ | ||||||||||||||
BNE |
Branch if Z not set | โ | ||||||||||||||
BEQ |
Branch if Z set | โ | ||||||||||||||
| jumping | JMP |
Jump | โ | โ | ||||||||||||
JSR |
Jump to subroutine | โ | ||||||||||||||
RTS |
Return from subroutine | Implied | ||||||||||||||
| flag | CLC |
Clear C | Implied | โ | ||||||||||||
SEC |
Set C | Implied | โ | |||||||||||||
CLI |
Clear I | Implied | โ | |||||||||||||
SEI |
Set I | Implied | โ | |||||||||||||
CLD |
Clear D | Implied | โ | |||||||||||||
SED |
Set D | Implied | โ | |||||||||||||
CLV |
Clear V | Implied | โ | |||||||||||||
| stack | TXS |
Transfer X to S | Implied | โ | โ | |||||||||||
TSX |
Transfer S to X | Implied | โ | โ | ||||||||||||
PHA |
Push A | Implied | โ | โ | ||||||||||||
PLA |
Pull A | Implied | โ | โ | ||||||||||||
PHP |
Push P | Implied | โ | โ | ||||||||||||
PLP |
Pull P | Implied | โ | โ | ||||||||||||
| register | TAX |
Transfer A to X | Implied | โ | โ | |||||||||||
TXA |
Transfer X To A | Implied | โ | โ | ||||||||||||
DEX |
Decrement X | Implied | โ | โ | ||||||||||||
INX |
Increase X | Implied | โ | โ | ||||||||||||
TAY |
Transfer A to Y | Implied | โ | โ | ||||||||||||
TYA |
Transfer Y To A | Implied | โ | โ | ||||||||||||
DEY |
Decrement Y | Implied | โ | โ | ||||||||||||
INY |
Increase Y | Implied | โ | โ | ||||||||||||
| other | BRK |
Break | Implied | |||||||||||||
NOP |
No operation | Implied | ||||||||||||||
RTI |
Return from interupt | Implied | โ | โ | โ | โ | โ | โ | ||||||||
2 Positive and negative numbers
Bytes can hold 256 values: $00 to $FF. If we directly translate that to decimal numbers, we can say a byte can contain the numbers 0 to 255.
For some operations we need negative numbers. This means we now have two kinds of numbers: positive numbers and negative numbers.
To store whether or not a number is negative, we use bit 7. This means that we have one less bit to use for the number itself, which also means that the highest number is no longer 255, but 127, $7F or %01111111.
The good thing is that we now also have negative numbers, the lowest being -128, $80 or %10000000.
3 Flags
P, the processor status register, holds six flags.
- N
- Negative flag
- P-bit 7
- Gets set when the last opcode resulted in a negative result or in a result where the last bit got set to 1.
- V
- Overflow flag
- P-bit 6
- Gets set when the last bit of a number gets changed while decreasing a negative number or increasing a positive number.
- D
- Decimal flag
- P-bit 3
- Can be set with
sedor cleared withcld. When set a byte will be used to save 2 decimal digits. The NES does not support this. - I
- Interrupt flag
- P-bit 2
- When set all interrupts other than the non-maskable interrupts are suppressed.
- Z
- Zero flag
- P-bit 1
- Gets set when the last opcode resulted in zero.
- C
- Carry flag
- P-bit 0
- Gets set when a number over- or underflows, except when the over- or underflow got caused by an increment- or decrement-instruction. It also gets set when bits are shifted.
Bits 4 and 5 are not used.
Some will say there is also a B-flag, on bit 4. This is not true. When P gets pushed to the stack, bit 4 of what is pushed to the stack will be set to 1 if it was pushed on the stack via PHP or BRK and otherwise it will be set to 0. This does not mean that P itself stores anything in bit 4.
When P gets pushed to the stack, bit 5 will always be equal to 1.
The structure of what gets on the stack can be visualised as follows: %NV1BDIZC.
4 Addressing modes
- Accumulator
- The accumulator is the target. The structure is:
OPC A. - Immediate
- A static, or immediate, value is the target. The structure is:
OPC #$7F. - Implied
- There is no target. The structure is:
OPC. - Relative
- When a singed byte is the target and is used as a relative offset. This is only used for branching. The structure is:
OPC $7F. - Absolute, non-indexed
- A 16-bit memory-address is the target. The structure is:
OPC $7F00. - Absolute, indexed
- A 16-bit memory-address is the target. The unsinged value of
XorYwill be added to that address to get the used address. The structure is:OPC $7F00, XorOPC $7F00, Y. - Zero page, non-indexed
- An 8-bit value is the target. This value will be used as an index for a memory-address in page 0. The structure is:
OPC $7F. - Zero page, indexed
- An 8-bit value is the target. The unsinged value of
Xwill be added to the value and be used as an index for a memory-address in page 0. The structure is:OPC $7F, X. - Indirect, non-indexed
- A 16-bit memory-address is the target. The address given will be used to fetch another address. That new address will be used. The structure is:
OPC ($7F00). - Indirect, indexed
A 8-bit value it the target. The behaviour is different based on if
XorYare given.- If
Xis given,Xwill be added to the value and the result will be used as an index in page 0 for the memory-address to use. The structure is:OPC ($7F, X). - If
Yis given, The value will be used as an index in page 0 for the stored memory-address.Ywill be added to that address to get the memory-address to use. The structure is:OPC ($7F), Y.
- If