Result:
Writing Multiplication Loop Start at: 0x801e
Writing Multiplication Done at: 0x8031
Writing Division Loop Start at: 0x803f
Writing Division Done at: 0x804d
Writing Division by Zero Handler at: 0x804e
Writing END Handler at: 0x8055
LDA Immediate: A = 5
STA Zero Page: memory[0x10] = 5
LDA Immediate: A = 3
STA Zero Page: memory[0x11] = 3
LDA Zero Page: A = 5 from 0x10
CLC: Carry Flag cleared
ADC Zero Page: A = 8
STA Zero Page: memory[0x12] = 8
LDA Zero Page: A = 5 from 0x10
SEC: Carry Flag set
SBC Zero Page: A = 2
STA Zero Page: memory[0x13] = 2
LDA Immediate: A = 0
STA Zero Page: memory[0x14] = 0
LDA Zero Page: A = 3 from 0x11
STA Zero Page: memory[0x15] = 3
LDX Zero Page: X = 3
CPX Immediate: X = 3, Value = 0
BEQ Branch not taken
LDA Zero Page: A = 0 from 0x14
CLC: Carry Flag cleared
ADC Zero Page: A = 5
STA Zero Page: memory[0x14] = 5
DEX: X = 2
STX Zero Page: memory[0x15] = 2
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 2
CPX Immediate: X = 2, Value = 0
BEQ Branch not taken
LDA Zero Page: A = 5 from 0x14
CLC: Carry Flag cleared
ADC Zero Page: A = a
STA Zero Page: memory[0x14] = a
DEX: X = 1
STX Zero Page: memory[0x15] = 1
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 1
CPX Immediate: X = 1, Value = 0
BEQ Branch not taken
LDA Zero Page: A = a from 0x14
CLC: Carry Flag cleared
ADC Zero Page: A = f
STA Zero Page: memory[0x14] = f
DEX: X = 0
STX Zero Page: memory[0x15] = 0
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
BEQ Branch taken to PC = 0x802e
JMP Absolute: PC set to 0x801e
LDX Zero Page: X = 0
CPX Immediate: X = 0, Value = 0
Results:
Operand1 (memory[0x10]): 5
Operand2 (memory[0x11]): 3
Addition result (memory[0x12]): 8
Subtraction result (memory[0x13]): 2
Multiplication result (memory[0x14]): f
Division quotient (memory[0x16]): 0
Division remainder (memory[0x17]): 0

Issue:
Division quotient (memory[0x16]): 0
Division remainder (memory[0x17]): 0
Code:
#include <iostream>
#include <cstdint>
#include <array>
#include <unordered_map>
#include <functional>
#include <iomanip>
#include <sstream>

// Класс памяти для обработки 64KB памяти
class Memory {
public:
    static const size_t SIZE = 65536;
    std::array<uint8_t, SIZE> data;
    Memory() {
        data.fill(0); // Инициализируем всю память нулями
    }

    uint8_t Read(uint16_t address) const {
        return data[address];
    }

    void Write(uint16_t address, uint8_t value) {
        data[address] = value;
    }
};

// Класс CPU, представляющий процессор 6502
class CPU {
public:
    // Регистры
    uint8_t A = 0; // Аккумулятор
    uint8_t X = 0; // Регистр X
    uint8_t Y = 0; // Регистр Y
    uint8_t SP = 0xFF; // Указатель стека (стек начинается с 0x0100)
    uint16_t PC = 0x8000; // Счётчик команд

    // Флаги состояния
    bool C = false; // Флаг переноса (Carry)
    bool Z = false; // Флаг нуля (Zero)
    bool I = false; // Флаг запрета прерываний (Interrupt Disable)
    bool D = false; // Флаг десятичного режима (Decimal Mode)
    bool B = false; // Флаг прерывания (Break Command)
    bool V = false; // Флаг переполнения (Overflow)
    bool N = false; // Флаг отрицательного числа (Negative)

    bool halted = false; // Флаг остановки

    using InstructionHandler = std::function<void(Memory&)>;
    void ExecuteInstruction(uint8_t opcode, Memory& memory);
    void InitializeInstructions();
    uint8_t Fetch(Memory& memory) {
        return memory.Read(PC++);
    }

private:
    std::unordered_map<uint8_t, InstructionHandler> instructionSet;
    void UpdateZeroAndNegativeFlags(uint8_t value) {
        Z = (value == 0);
        N = (value & 0x80) != 0;
    }

    void Push(uint8_t value, Memory& memory) {
        memory.Write(0x0100 + SP, value);
        SP--;
    }

    uint8_t Pull(Memory& memory) {
        SP++;
        return memory.Read(0x0100 + SP);
    }
};

// Инициализация набора инструкций (таблица опкодов)
void CPU::InitializeInstructions() {
    // LDA Immediate
    instructionSet[0xA9] = [this](Memory& memory) {
        uint8_t value = Fetch(memory);
        A = value;
        UpdateZeroAndNegativeFlags(A);
        std::cout << "LDA Immediate: A = " << +A << "\n";
        };

    // JMP Absolute
    instructionSet[0x4C] = [this](Memory& memory) {
        uint8_t low = Fetch(memory);
        uint8_t high = Fetch(memory);
        uint16_t address = low | (high << 8);
        PC = address;
        std::cout << "JMP Absolute: PC set to 0x" << std::hex << address << "\n";
        };

    // DEX
    instructionSet[0xCA] = [this](Memory& memory) {
        X--;
        UpdateZeroAndNegativeFlags(X);
        std::cout << "DEX: X = " << +X << "\n";
        };

    // LDA Zero Page
    instructionSet[0xA5] = [this](Memory& memory) {
        uint8_t addr = Fetch(memory);
        A = memory.Read(addr);
        UpdateZeroAndNegativeFlags(A);
        std::cout << "LDA Zero Page: A = " << +A << " from 0x" << std::hex << +addr << "\n";
        };

    // SBC Zero Page
    instructionSet[0xE5] = [this](Memory& memory) {
        uint8_t addr = Fetch(memory);
        uint8_t value = memory.Read(addr);
        uint16_t temp = A - value - (C ? 0 : 1);
        C = A >= (value + (!C ? 1 : 0));
        V = ((A ^ value) & (A ^ temp) & 0x80) != 0;
        A = temp & 0xFF;
        UpdateZeroAndNegativeFlags(A);
        std::cout << "SBC Zero Page: A = " << +A << "\n";
        };

    // LDX Zero Page
    instructionSet[0xA6] = [this](Memory& memory) {
        uint8_t addr = Fetch(memory);
        X = memory.Read(addr);
        UpdateZeroAndNegativeFlags(X);
        std::cout << "LDX Zero Page: X = " << +X << "\n";
        };

    // CPX Immediate
    instructionSet[0xE0] = [this](Memory& memory) {
        uint8_t value = Fetch(memory);
        uint8_t temp = X - value;
        C = X >= value;
        Z = (temp == 0);
        N = (temp & 0x80) != 0;
        std::cout << "CPX Immediate: X = " << +X << ", Value = " << +value << "\n";
        };

    // STX Zero Page
    instructionSet[0x86] = [this](Memory& memory) {
        uint8_t addr = Fetch(memory);
        memory.Write(addr, X);
        std::cout << "STX Zero Page: memory[0x" << std::hex << +addr << "] = " << +X << "\n";
        };

    // LDA Absolute
    instructionSet[0xAD] = [this](Memory& memory) {
        uint8_t low = Fetch(memory);
        uint8_t high = Fetch(memory);
        uint16_t address = low | (high << 8);
        A = memory.Read(address);
        UpdateZeroAndNegativeFlags(A);
        std::cout << "LDA Absolute: A = " << +A << " from 0x" << std::hex << address << "\n";
        };

    // STA Zero Page
    instructionSet[0x85] = [this](Memory& memory) {
        uint8_t addr = Fetch(memory);
        memory.Write(addr, A);
        std::cout << "STA Zero Page: memory[0x" << std::hex << +addr << "] = " << +A << "\n";
        };

    // STA Absolute
    instructionSet[0x8D] = [this](Memory& memory) {
        uint8_t low = Fetch(memory);
        uint8_t high = Fetch(memory);
        uint16_t address = low | (high << 8);
        memory.Write(address, A);
        std::cout << "STA Absolute: memory[0x" << std::hex << address << "] = " << +A << "\n";
        };

    // ADC Immediate
    instructionSet[0x69] = [this](Memory& memory) {
        uint8_t value = Fetch(memory);
        uint16_t result = A + value + (C ? 1 : 0);
        V = (~(A ^ value) & (A ^ result) & 0x80) != 0;
        C = result > 0xFF;
        A = result & 0xFF;
        UpdateZeroAndNegativeFlags(A);
        std::cout << "ADC Immediate: A = " << +A << "\n";
        };

    // ADC Zero Page
    instructionSet[0x65] = [this](Memory& memory) {
        uint8_t addr = Fetch(memory);
        uint8_t value = memory.Read(addr);
        uint16_t result = A + value + (C ? 1 : 0);
        V = (~(A ^ value) & (A ^ result) & 0x80) != 0;
        C = result > 0xFF;
        A = result & 0xFF;
        UpdateZeroAndNegativeFlags(A);
        std::cout << "ADC Zero Page: A = " << +A << "\n";
        };

    // AND Immediate
    instructionSet[0x29] = [this](Memory& memory) {
        uint8_t value = Fetch(memory);
        A &= value;
        UpdateZeroAndNegativeFlags(A);
        std::cout << "AND Immediate: A = " << +A << "\n";
        };

    // ORA Immediate
    instructionSet[0x09] = [this](Memory& memory) {
        uint8_t value = Fetch(memory);
        A |= value;
        UpdateZeroAndNegativeFlags(A);
        std::cout << "ORA Immediate: A = " << +A << "\n";
        };

    // EOR Immediate
    instructionSet[0x49] = [this](Memory& memory) {
        uint8_t value = Fetch(memory);
        A ^= value;
        UpdateZeroAndNegativeFlags(A);
        std::cout << "EOR Immediate: A = " << +A << "\n";
        };

    // ASL Accumulator
    instructionSet[0x0A] = [this](Memory& memory) {
        C = (A & 0x80) != 0;
        A <<= 1;
        UpdateZeroAndNegativeFlags(A);
        std::cout << "ASL Accumulator: A = " << +A << ", C = " << C << "\n";
        };

    // LSR Accumulator
    instructionSet[0x4A] = [this](Memory& memory) {
        C = (A & 0x01) != 0;
        A >>= 1;
        UpdateZeroAndNegativeFlags(A);
        std::cout << "LSR Accumulator: A = " << +A << ", C = " << C << "\n";
        };

    // ROL Accumulator
    instructionSet[0x2A] = [this](Memory& memory) {
        bool oldC = C;
        C = (A & 0x80) != 0;
        A = (A << 1) | (oldC ? 1 : 0);
        UpdateZeroAndNegativeFlags(A);
        std::cout << "ROL Accumulator: A = " << +A << ", C = " << C << "\n";
        };

    // ROR Accumulator
    instructionSet[0x6A] = [this](Memory& memory) {
        bool oldC = C;
        C = (A & 0x01) != 0;
        A = (A >> 1) | (oldC ? 0x80 : 0x00);
        UpdateZeroAndNegativeFlags(A);
        std::cout << "ROR Accumulator: A = " << +A << ", C = " << C << "\n";
        };

    // CMP Immediate
    instructionSet[0xC9] = [this](Memory& memory) {
        uint8_t value = Fetch(memory);
        uint8_t temp = A - value;
        C = A >= value;
        Z = (temp == 0);
        N = (temp & 0x80) != 0;
        std::cout << "CMP Immediate: A = " << +A << ", Value = " << +value << "\n";
        };

    // CMP Zero Page
    instructionSet[0xC5] = [this](Memory& memory) {
        uint8_t addr = Fetch(memory);
        uint8_t value = memory.Read(addr);
        uint8_t temp = A - value;
        C = A >= value;
        Z = (temp == 0);
        N = (temp & 0x80) != 0;
        std::cout << "CMP Zero Page: A = " << +A << ", Value = " << +value << "\n";
        };

    // DEC Zero Page
    instructionSet[0xC6] = [this](Memory& memory) {
        uint8_t addr = Fetch(memory);
        uint8_t value = memory.Read(addr);
        value--;
        memory.Write(addr, value);
        Z = (value == 0);
        N = (value & 0x80) != 0;
        std::cout << "DEC Zero Page: memory[0x" << std::hex << +addr << "] = " << +value << "\n";
        };

    // INC Zero Page
    instructionSet[0xE6] = [this](Memory& memory) {
        uint8_t addr = Fetch(memory);
        uint8_t value = memory.Read(addr);
        value++;
        memory.Write(addr, value);
        Z = (value == 0);
        N = (value & 0x80) != 0;
        std::cout << "INC Zero Page: memory[0x" << std::hex << +addr << "] = " << +value << "\n";
        };

    // BEQ Relative
    instructionSet[0xF0] = [this](Memory& memory) {
        int8_t offset = static_cast<int8_t>(Fetch(memory));
        if (Z) {
            PC += offset;
            std::cout << "BEQ Branch taken to PC = 0x" << std::hex << PC << "\n";
        }
        else {
            std::cout << "BEQ Branch not taken\n";
        }
        };

    // BNE Relative
    instructionSet[0xD0] = [this](Memory& memory) {
        int8_t offset = static_cast<int8_t>(Fetch(memory));
        if (!Z) {
            PC += offset;
            std::cout << "BNE Branch taken to PC = 0x" << std::hex << PC << "\n";
        }
        else {
            std::cout << "BNE Branch not taken\n";
        }
        };

    // BCS Relative
    instructionSet[0xB0] = [this](Memory& memory) {
        int8_t offset = static_cast<int8_t>(Fetch(memory));
        if (C) {
            PC += offset;
            std::cout << "BCS Branch taken to PC = 0x" << std::hex << PC << "\n";
        }
        else {
            std::cout << "BCS Branch not taken\n";
        }
        };

    // BCC Relative
    instructionSet[0x90] = [this](Memory& memory) {
        int8_t offset = static_cast<int8_t>(Fetch(memory));
        if (!C) {
            PC += offset;
            std::cout << "BCC Branch taken to PC = 0x" << std::hex << PC << "\n";
        }
        else {
            std::cout << "BCC Branch not taken\n";
        }
        };

    // BMI Relative
    instructionSet[0x30] = [this](Memory& memory) {
        int8_t offset = static_cast<int8_t>(Fetch(memory));
        if (N) {
            PC += offset;
            std::cout << "BMI Branch taken to PC = 0x" << std::hex << PC << "\n";
        }
        else {
            std::cout << "BMI Branch not taken\n";
        }
        };

    // BPL Relative
    instructionSet[0x10] = [this](Memory& memory) {
        int8_t offset = static_cast<int8_t>(Fetch(memory));
        if (!N) {
            PC += offset;
            std::cout << "BPL Branch taken to PC = 0x" << std::hex << PC << "\n";
        }
        else {
            std::cout << "BPL Branch not taken\n";
        }
        };

    // BVS Relative
    instructionSet[0x70] = [this](Memory& memory) {
        int8_t offset = static_cast<int8_t>(Fetch(memory));
        if (V) {
            PC += offset;
            std::cout << "BVS Branch taken to PC = 0x" << std::hex << PC << "\n";
        }
        else {
            std::cout << "BVS Branch not taken\n";
        }
        };

    // BVC Relative
    instructionSet[0x50] = [this](Memory& memory) {
        int8_t offset = static_cast<int8_t>(Fetch(memory));
        if (!V) {
            PC += offset;
            std::cout << "BVC Branch taken to PC = 0x" << std::hex << PC << "\n";
        }
        else {
            std::cout << "BVC Branch not taken\n";
        }
        };

    // CLC (Clear Carry Flag)
    instructionSet[0x18] = [this](Memory& memory) {
        C = false;
        std::cout << "CLC: Carry Flag cleared\n";
        };

    // SEC (Set Carry Flag)
    instructionSet[0x38] = [this](Memory& memory) {
        C = true;
        std::cout << "SEC: Carry Flag set\n";
        };

    // CLI (Clear Interrupt Disable)
    instructionSet[0x58] = [this](Memory& memory) {
        I = false;
        std::cout << "CLI: Interrupt Disable Flag cleared\n";
        };

    // SEI (Set Interrupt Disable)
    instructionSet[0x78] = [this](Memory& memory) {
        I = true;
        std::cout << "SEI: Interrupt Disable Flag set\n";
        };

    // CLV (Clear Overflow Flag)
    instructionSet[0xB8] = [this](Memory& memory) {
        V = false;
        std::cout << "CLV: Overflow Flag cleared\n";
        };

    // CLD (Clear Decimal Mode)
    instructionSet[0xD8] = [this](Memory& memory) {
        D = false;
        std::cout << "CLD: Decimal Mode Flag cleared\n";
        };

    // SED (Set Decimal Mode)
    instructionSet[0xF8] = [this](Memory& memory) {
        D = true;
        std::cout << "SED: Decimal Mode Flag set\n";
        };

    // BIT Zero Page
    instructionSet[0x24] = [this](Memory& memory) {
        uint8_t addr = Fetch(memory);
        uint8_t value = memory.Read(addr);
        Z = ((A & value) == 0);
        V = (value & 0x40) != 0;
        N = (value & 0x80) != 0;
        std::cout << "BIT Zero Page: Z = " << Z << ", V = " << V << ", N = " << N << "\n";
        };

    // NOP
    instructionSet[0xEA] = [this](Memory& memory) {
        std::cout << "NOP: No Operation\n";
        };

    // BRK
    instructionSet[0x00] = [this](Memory& memory) {
        Push((PC >> 8) & 0xFF, memory); // Push high byte of PC
        Push(PC & 0xFF, memory);        // Push low byte of PC
        uint8_t status = (C ? 0x01 : 0x00) |
            (Z ? 0x02 : 0x00) |
            (I ? 0x04 : 0x00) |
            (D ? 0x08 : 0x00) |
            (B ? 0x10 : 0x00) |
            (V ? 0x40 : 0x00) |
            (N ? 0x80 : 0x00);
        Push(status, memory);
        I = true; // Disable interrupts
        PC = 0xFFFE; // Обычно BRK устанавливает PC на вектор прерывания
        std::cout << "BRK: Software interrupt, PC set to 0x" << std::hex << PC << "\n";
        halted = true; // Устанавливаем флаг остановки
        };

    // RTI
    instructionSet[0x40] = [this](Memory& memory) {
        uint8_t status = Pull(memory);
        C = status & 0x01;
        Z = status & 0x02;
        I = status & 0x04;
        D = status & 0x08;
        B = status & 0x10;
        V = status & 0x40;
        N = status & 0x80;
        uint8_t low = Pull(memory);
        uint8_t high = Pull(memory);
        PC = (high << 8) | low;
        std::cout << "RTI: Returning to PC = 0x" << std::hex << PC << "\n";
        };
}

// Выполнение инструкции на основе полученного опкода
void CPU::ExecuteInstruction(uint8_t opcode, Memory& memory) {
    if (instructionSet.find(opcode) != instructionSet.end()) {
        instructionSet[opcode](memory);
    }
    else {
        std::cerr << "Unknown opcode: 0x" << std::hex << +opcode << "\n";
        halted = true; // Останавливаем выполнение при неизвестном опкоде
    }
}

int main() {
    Memory memory;
    CPU cpu;
    cpu.InitializeInstructions();

    // Устанавливаем счётчик команд на начальный адрес
    cpu.PC = 0x8000;

    // Записываем инструкции в память
    uint16_t addr = 0x8000;

    // Загрузка операндов
    memory.Write(addr++, 0xA9); // LDA #$05
    memory.Write(addr++, 0x05); // Operand1 = 5
    memory.Write(addr++, 0x85); // STA $10
    memory.Write(addr++, 0x10);

    memory.Write(addr++, 0xA9); // LDA #$03
    memory.Write(addr++, 0x03); // Operand2 = 3
    memory.Write(addr++, 0x85); // STA $11
    memory.Write(addr++, 0x11);

    // Сложение
    memory.Write(addr++, 0xA5); // LDA $10
    memory.Write(addr++, 0x10);
    memory.Write(addr++, 0x18); // CLC
    memory.Write(addr++, 0x65); // ADC $11
    memory.Write(addr++, 0x11);
    memory.Write(addr++, 0x85); // STA $12
    memory.Write(addr++, 0x12);

    // Вычитание
    memory.Write(addr++, 0xA5); // LDA $10
    memory.Write(addr++, 0x10);
    memory.Write(addr++, 0x38); // SEC
    memory.Write(addr++, 0xE5); // SBC $11
    memory.Write(addr++, 0x11);
    memory.Write(addr++, 0x85); // STA $13
    memory.Write(addr++, 0x13);

    // Инициализация умножения
    memory.Write(addr++, 0xA9); // LDA #$00
    memory.Write(addr++, 0x00);
    memory.Write(addr++, 0x85); // STA $14 (результат умножения)
    memory.Write(addr++, 0x14);
    memory.Write(addr++, 0xA5); // LDA $11 (счётчик умножения)
    memory.Write(addr++, 0x11);
    memory.Write(addr++, 0x85); // STA $15 (счётчик)
    memory.Write(addr++, 0x15);

    // MULT_LOOP:
    uint16_t mult_loop_addr = addr;
    std::cout << "Writing Multiplication Loop Start at: 0x" << std::hex << mult_loop_addr << "\n";
    memory.Write(addr++, 0xA6); // LDX $15
    memory.Write(addr++, 0x15);
    memory.Write(addr++, 0xE0); // CPX #$00
    memory.Write(addr++, 0x00);
    memory.Write(addr++, 0xF0); // BEQ MULT_DONE
    memory.Write(addr++, 0x0A); // Смещение к MULT_DONE (адрес = 0x8031)

    memory.Write(addr++, 0xA5); // LDA $14 (текущий результат умножения)
    memory.Write(addr++, 0x14);
    memory.Write(addr++, 0x18); // CLC
    memory.Write(addr++, 0x65); // ADC $10 (добавляем Operand1)
    memory.Write(addr++, 0x10);
    memory.Write(addr++, 0x85); // STA $14 (сохраняем результат)
    memory.Write(addr++, 0x14);
    memory.Write(addr++, 0xCA); // DEX
    memory.Write(addr++, 0x86); // STX $15 (сохраняем счётчик)
    memory.Write(addr++, 0x15);
    memory.Write(addr++, 0x4C); // JMP Absolute
    memory.Write(addr++, (uint8_t)(mult_loop_addr & 0xFF)); // Low byte
    memory.Write(addr++, (uint8_t)((mult_loop_addr >> 8) & 0xFF)); // High byte

    // MULT_DONE:
    uint16_t mult_done_addr = addr;
    std::cout << "Writing Multiplication Done at: 0x" << std::hex << mult_done_addr << "\n";
    memory.Write(addr++, 0xA9); // LDA #$00
    memory.Write(addr++, 0x00);
    memory.Write(addr++, 0x85); // STA $16 (частное деления)
    memory.Write(addr++, 0x16);
    memory.Write(addr++, 0xA5); // LDA $10 (делимое)
    memory.Write(addr++, 0x10);
    memory.Write(addr++, 0x85); // STA $17 (остаток)
    memory.Write(addr++, 0x17);

    // Проверка деления на ноль
    memory.Write(addr++, 0xA5); // LDA $11 (делитель)
    memory.Write(addr++, 0x11);
    memory.Write(addr++, 0xC9); // CMP #$00
    memory.Write(addr++, 0x00);
    memory.Write(addr++, 0xF0); // BEQ DIV_ZERO
    memory.Write(addr++, 0x0C); // Смещение к DIV_ZERO (адрес = 0x804f)

    // DIV_LOOP:
    uint16_t div_loop_addr = addr;
    std::cout << "Writing Division Loop Start at: 0x" << std::hex << div_loop_addr << "\n";
    memory.Write(addr++, 0xA5); // LDA $17 (остаток)
    memory.Write(addr++, 0x17);
    memory.Write(addr++, 0x38); // SEC
    memory.Write(addr++, 0xE5); // SBC $11 (вычитаем делитель)
    memory.Write(addr++, 0x11);
    memory.Write(addr++, 0x90); // BCC DIV_DONE
    memory.Write(addr++, 0x07); // Смещение к DIV_DONE (адрес = 0x804e)
    memory.Write(addr++, 0x85); // STA $17 (новый остаток)
    memory.Write(addr++, 0x17);
    memory.Write(addr++, 0xE6); // INC $16 (увеличиваем частное)
    memory.Write(addr++, 0x16);
    memory.Write(addr++, 0x4C); // JMP Absolute
    memory.Write(addr++, (uint8_t)(div_loop_addr & 0xFF)); // Low byte
    memory.Write(addr++, (uint8_t)((div_loop_addr >> 8) & 0xFF)); // High byte

    // DIV_DONE:
    uint16_t div_done_addr = addr;
    std::cout << "Writing Division Done at: 0x" << std::hex << div_done_addr << "\n";
    memory.Write(addr++, 0x00); // BRK

    // DIV_ZERO:
    uint16_t div_zero_addr = addr;
    std::cout << "Writing Division by Zero Handler at: 0x" << std::hex << div_zero_addr << "\n";
    memory.Write(addr++, 0xA9); // LDA #$FF
    memory.Write(addr++, 0xFF);
    memory.Write(addr++, 0x85); // STA $16 (частное)
    memory.Write(addr++, 0x16);
    memory.Write(addr++, 0x85); // STA $17 (остаток)
    memory.Write(addr++, 0x17);
    memory.Write(addr++, 0x00); // BRK

    // END:
    uint16_t end_label_addr = addr;
    std::cout << "Writing END Handler at: 0x" << std::hex << end_label_addr << "\n";
    memory.Write(addr++, 0x00); // BRK

    // Выполняем программу до остановки или достижения максимального количества инструкций
    bool running = true;
    int instructionCount = 0;
    const int MAX_INSTRUCTIONS = 1000; // Можно изменить при необходимости

    while (running && instructionCount < MAX_INSTRUCTIONS) {
        uint8_t opcode = cpu.Fetch(memory);
        cpu.ExecuteInstruction(opcode, memory);
        instructionCount++;

        // Проверяем, установлена ли флаг остановки
        if (cpu.halted) {
            running = false;
            std::cout << "Program halted.\n";
        }
    }

    // Вывод результатов
    std::cout << "Results:\n";
    std::cout << "Operand1 (memory[0x10]): " << +memory.Read(0x10) << "\n";
    std::cout << "Operand2 (memory[0x11]): " << +memory.Read(0x11) << "\n";
    std::cout << "Addition result (memory[0x12]): " << +memory.Read(0x12) << "\n";
    std::cout << "Subtraction result (memory[0x13]): " << +memory.Read(0x13) << "\n";
    std::cout << "Multiplication result (memory[0x14]): " << std::hex << +memory.Read(0x14) << "\n";
    std::cout << "Division quotient (memory[0x16]): " << +memory.Read(0x16) << "\n";
    std::cout << "Division remainder (memory[0x17]): " << +memory.Read(0x17) << "\n";

    return 0;
}
Fix problem.