Abbrevations | A | X | Y | S | P | PC |
---|---|---|---|---|---|---|
Names | Accumulator | X Register | Y Register | Stack Pointer | Status Register | Program Counter |
Size | 8-bit | 8-bit | 8-bit | 8-bit | 8-bit | 16-bit |
Comments | general purpose, ALU | general purpose, index register | general purpose, index register | used to push to/ pull from tde stack | contains several flags; see below | address of the current instruction |
Bit | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
---|---|---|---|---|---|---|---|---|
Abbrevation | N | V | - | B | D | I | Z | C |
Name | Negative | Overflow | Unused | Unused | Decimal | Interrupt Disable | Zero | Carry |
Set/Reset | CLV | SED, CLD | SEI, CLI | SEC, CLC | ||||
Comment | bit 7 of the result of an operation (sign bit) |
set by ADC and SBC if signed result would have overflown | unused; always 1 |
technically unused; but when P is pushed to the stack, this bit may be either
0 or 1 , depending on the instruction:
Note: when P is pushed, the
I flag is set as well (unless the operation was PHP)
|
no effect on the NES |
when set, all interrupts except NMI are inhibited; automatically set when an IRQ occurs, and restored by the interrupt handler's RTI clearing this flag when an IRQ is pending causes the interrupt to trigger immediately |
set if the result of an operation is equal to 0 |
set to the carry of the addition by ADC; set if no borrow was the result ("greater than or equal to") by SBC and CMP; set to the bit shifted out by ASL, LSR, ROL, and ROR |
PC = (PCH << 8) | PCL
EA = (EAH << 8) | EAL
BA = (BAH << 8) | BAL
0th
cycle is the 1st
cycle of the next instruction!
[address]
: Read memory at a given address
arg
: The additional data of an instruction (8-bit or 16-bit, if present)++S
: increment the stack pointer, then use it (pre-increment)S--
: first use the stack pointer, then decrement it afterwards (post-decrement)PHP
or ASL A
data = A
(depending on the operation; not actually stored in the data register)
ORA #$69
data = arg
(8-bit)
JMP ($CAFE)
PC = [arg]
(16-bit)
BEQ label
(label
is converted into a signed offset by the compiler)PC = PC + arg
(8-bit, signed)
ADC $4269
data = [arg]
(16-bit)
I
represents either the X or Y register, depending on the mode.LDX $1234,X
or
EOR $5566,Y
data = [arg + I]
(16-bit)
CMP $7F
data = [arg] (8-bit)
I
represents either the X or Y register, depending on the mode.STY $EE,X
or
LAX $DD,Y
data = [(arg + I) & $FF]
(8-bit)
LDA ($AB,X)
data = [[(arg + X) & $FF] + ([(arg + X + 1) & $FF] << 8)]
(8-bit)
SBC ($EF),X
data = [[arg] + ([(arg + 1) & $FF] << 8) + Y]
(8-bit)
JMP abs
)
[S--] = PCH; [S--] = PCL; [S--] = P; PC = [$FFFE] | ([$FFFF] << 8)
PC = ([++S] << 8) | [++S]
A/P = [++S]
JSR $BEEF
[S--] = PCH; [S--] = PCL; PC = arg
(16-bit)
JMP $BABE
PC = arg
(16-bit)
[address]
: Read memory at a given address
arg
: The additional data of an instruction (8-bit or 16-bit, if present)++S
: increment the stack pointer, then use it (pre-increment)S--
: first use the stack pointer, then decrement it afterwards (post-decrement)#
: the fetched value (depending on the Addressing mode)Mnemonic | Operation | NV-BDIZC |
---|
Mnemonic | Operation | NV-BDIZC | Stability |
---|
SLO := ASL + ORA
RLA := ROL + AND
SRE := LSR + EOR
RRA := ROR + ADC
LAX := LDA + LDX
DCP := DEC + CMP
ISC := INC + SBC
ANC := AND + ASL
ANC := AND + ROL
ALR := AND + LSR
ARR := AND + ROR
XAA := TXA + AND
LAX := LDA + TAX
SBC := SBC + NOP
A&X
) is
performed by putting the A and X register onto the bus at the same time.A
) technically
performs an AND operation, but puts bit 7 into the carry
(like an ASL/ROL operation would).(A)>>1
) perform a step
between the AND and the ROR: V is set according to
(A)+#
; bit 0 does not go into the carry, but
bit 7 is exchanged with the carry.A&X-#
) performs
a CMP and DEX at the same time.
The minus therefore sets the flags like a CMP (not SBC) would&H
operation, with H
begin the high byte of the provided address + 1.
Sometimes this part of the operation is not executed, therefore they are considered unstable.
Also page boundary crossing does not work as expected.$00
, $FF
, $EE
etc.). This
adds a (A|magic)&
term to the equation and effectively results in the following operations: