Open main menu

CDOT Wiki β

Changes

6502 Instructions - Introduction

146 bytes added, 01:59, 11 September 2023
Miscellaneous Instructions
==== Push/Pull on the Stack ====
When a value is pushed to the stack, the stack pointer register (SP) is decremented and the selected register is written to memory location $0100+SPand the stack pointer register (SP) is decremented.
When a value is pulled from the stack, the stack pointer register (SP) is incremented and the selected register is loaded from memory location $0100+SP and the stack pointer register (SP) is incremented.
There are two instructions to push data onto the stack:
'''For full details on all of the arithmetic and bitwise instructions, see the [[6502 Math]] page.'''
The 6502 has rudimentry basic addition and subtraction instructions, which operate on the accumulator (A):
ADC ; add with carry
The A, X, and Y registers can be directly compared with immediate or memory values:
CMP ; compare (accumulator) CPX ; compare (X register) CPY ; compare (Y register)
These operations are performed by subtraction. The appropriate condition flags are set, and the result of the subtraction is discarded. Conditional branch instructions can be used to alter program flow based on the results of the comparisons.
The 6502 provides instructions for setting and clearing various condition flags:
CLC ; clear carry flag (C) - required before using ADC(for single-byte and lowest-byte)
CLD ; clear decimal flag (D) - switches into binary math mode
CLI ; clear interrupt disable (I) - enables processor interrupts
CLV ; clear overflow flag (V)
SEC ; set carry flag (C) - required before using SBC(for single-byte and lowest-byte)
SED ; set decimal flag (D) - switches into decimal math mode
SEI ; set interrupt disable - turns off processor interrupts
NOP ; no operation
The <code>NOP</code> instruction does nothing. It can be used to "comment-out" pad codefor alignment purposes, or unwanted code can be overwritten in situ with this opcode to disable it.
== Resources ==