6502 Microprocessor
Assembly Language
Arsitektur dan Organisasi Komputer
Sekolah Tinggi Intelijen Negara
6502 microprocessors
Why 6502
• 6502 assembly has fewer instructions than modern assembly
• The instructions on the 6502 are varied and compared to other
processors at the time offer a lot of options
• The 6502 was incredibly popular
The 6502 Architecture
• The 6502 is an 8-bit microprocessor that follows the
memory oriented design philosophy of the Motorola
6800
• The 6502 handles data in its registers, each of which
holds one byte (8-bits) of data
• 6502 registers:
• accumulator (A) - Handles all arithmetic and logic. The real
heart of the system
• X and Y - General purpose registers with limited abilities.
• S - Stack pointer.
• P - Processor status. Holds the result of tests and flags
Stack Pointer
• When the microprocessor executes a JSR (Jump to SubRoutine)
instruction it needs to know where to return when finished
• The 6502 keeps this information in low memory from $0100 to $01FF
and uses the stack pointer as an offset
• The stack grows down from $01FF and makes it possible to nest
subroutines up to 128 levels deep
Processor Status flag, 0/1 = reset/set
+---+---+---+---+---+---+---+---+
N = NEGATIVE. Set if bit 7 of the accumulator is set.
V = OVERFLOW. Set if the addition of two like-signed numbers or the
subtraction of two unlike-signed numbers produces a result
greater than +127 or less than -128.
B = BRK COMMAND. Set if an interrupt caused by a BRK, reset if
caused by an external interrupt.
D = DECIMAL MODE. Set if decimal mode active.
I = IRQ DISABLE. Set if maskable interrupts are disabled.
Z = ZERO. Set if the result of the last operation (load/inc/dec/
add/sub) was zero.
C = CARRY. Set if the add produced a carry, or if the subtraction
produced a borrow. Also holds bits after a logical shift.
Accumulator
• The majority of the 6502's business makes use of the
accumulator.
• All addition and subtraction is done in the accumulator
• It also handles the majority of the logical comparisons (is A >
B ?) and logical bit shifts
X and Y
• These are index registers often used to hold offsets to
memory locations
• They can also be used for holding needed values
• Much of their use lies in supporting some of the addressing
modes
Addressing Mode
The 6502 Instruction Set
• There are 56 instructions in the 6502, and more in the 65C02
• Many instructions make use of more than one addressing mode and
each instruction/addressing mode combination has a particular
hexadecimal opcode that specifies it exactly
• Some 6502 instructions make use of bitwise logic. This includes AND,
OR, and EOR (Exclusive-OR)
• Other 6502 instructions shift bits to the right or the left or rotate them right
or left
• Note that shifting to the left by one bit is the same as multiplying by 2 and
that shifting right by one bit is the same as dividing by 2
• The 6502 instructions fall naturally into 10 groups with two odd-ball
instructions NOP and BRK:
• Load and Store Instructions
• Arithmetic Instructions
• Increment and Decrement Instructions
• Logical Instructions
• Jump, Branch, Compare and Test Bits Instructions
• Shift and Rotate Instructions
• Transfer Instructions
• Stack Instructions
• Subroutine Instructions
• Set/Reset Instructions
• NOP/BRK Instructions