6502 image from https://www pagetable com/?p=1295 “Group two” shift/rotate, load/store X; fewer modes 5E 80 42 LSR $4280,X ;Logical Shift Right
Previous PDF | Next PDF |
[PDF] Advanced 6502 Assembly Language Programming on the Apple //e
6502 image from https://www pagetable com/?p=1295 “Group two” shift/rotate, load/store X; fewer modes 5E 80 42 LSR $4280,X ;Logical Shift Right
[PDF] The 6502 Instruction Set
6502-Conj-de-Instrucoes doc 1 © Kevin Wilson The 6502 Arithmetic Shift Left N,Z,C LSR Logical Shift Right N,Z,C ROL Rotate Left N,Z,C ROR Rotate
[PDF] 6502 Instant Reference Card - Atarimania
2 Arithmetic shift left Zero Page LDY nn,X Load Y ASL A Arithmetic shift left Accumulator LSR nn Logical shift right ASL n,X Arithmetic shift left Zero Page X
[PDF] Micro Logic 6502 Quick Reference Cardpdf - Apple Asimov
6502 (65XX) MICRO CHART **2 bytes must not cross page boundary 6502 Pins M A, Y, X, S, P = 1 byte Only PC is 2 bytes O 3 Logical shift right BEQ n
[PDF] Synertek Programming manual - 6502org
"All Rights Reserved" -- SYNERTEK CHAPTER 2 THE DATA BUS, ACCUMULATOR AND ARITHMETIC UNIT LSR--Logical Shift Right 148
[PDF] Programming the 6502, Rodney zaks - Retro Computing
The arithmetic logical unit (ALU) appears on the right of the il lustration The two numbers, correctly shifted, are then added and the sum is 276 This is simple
Appendix 1: 6502 Instruction Set
ing how arithmetic may be performed upon such numbers The number just after the point: that is, move it right or left until all digits to the left of the point a time and shift them accordingly, and this can also generate interrupts In the BBC
5 The Registers
To enable the 6502 (65C02) to carry out its various operations, it contains arithmetic and logical operations are carried out through it Logical shift right
[PDF] 6502 Introduction
18 sept 2019 · Computer Systems Fundamentals: 6502 Introduction Shift and rotate, e g , 00001111 → 00011110 LSR (Logical Shift Right) use carry bit
[PDF] 6502 asm opcodes
[PDF] 6502 asm tutorial
[PDF] 6502 asr
[PDF] 6502 assembler online
[PDF] 6502 assembly apple ii
[PDF] 6502 assembly code
[PDF] 6502 assembly example
[PDF] 6502 assembly jsr
[PDF] 6502 assembly language programming
[PDF] 6502 assembly language programming book
[PDF] 6502 assembly language tutorial
[PDF] 6502 assembly tutorial pdf
[PDF] 6502 block diagram pdf
[PDF] 6502 board kit
AdvancedAssembly
Programming
for theApple IIStephen A. Edwards6502 image fromhttps://www.pagetable.com/?p=1295
6502 image fromhttps://www.pagetable.com/?p=1295
DATA BUSADDR.
ADDRESS BUS
65024021222324252627282930313233343536373839
1201918171615141312111098765432
V SSA12A13A14A15D7D6D5D4D3D2D1D0
(IN) SO V SSA11A10A9A8A7A6A5A4A3A2A1A0V
CCSYNCRDY
(OUT)1IRQNMI
R/W 02 (OUT)RESAfter Bill Bertram, Wikipedia
The 6502 Programmer"s Model
07AACCUMULATOR
YINDEX REGISTERXINDEX REGISTER
15PCLPCHPROGRAM COUNTER
S1STACK POINTER
STATUS REGISTERC
CarryZ
ZeroIInterrupt DisableD
Decimal ModeB
BreakV
OverflowN
Negative
The 6502 Programmer"s Model
07AACCUMULATOR
YINDEX REGISTERXINDEX REGISTER
15PCLPCHPROGRAM COUNTER
S1STACK POINTER
STATUS REGISTERC
CarryZ
ZeroIInterrupt DisableD
Decimal ModeB
BreakV
OverflowN
Negative
The 6502 Programmer"s Model
07AACCUMULATOR
YINDEX REGISTERXINDEX REGISTER
15PCLPCHPROGRAM COUNTER
S1STACK POINTER
STATUS REGISTERC
CarryZ
ZeroIInterrupt DisableD
Decimal ModeB
BreakV
OverflowN
Negative
The 6502 Programmer"s Model
07AACCUMULATOR
YINDEX REGISTERXINDEX REGISTER
15PCLPCHPROGRAM COUNTER
S1STACK POINTER
STATUS REGISTERC
CarryZ
ZeroIInterrupt DisableD
Decimal ModeB
BreakV
OverflowN
Negative
The 6502 Programmer"s Model
07AACCUMULATOR
YINDEX REGISTERXINDEX REGISTER
15PCLPCHPROGRAM COUNTER
S1STACK POINTER
STATUS REGISTERC
CarryZ
ZeroIInterrupt DisableD
Decimal ModeB
BreakV
OverflowN
Negative
The 6502 Programmer"s Model
07AACCUMULATOR
YINDEX REGISTERXINDEX REGISTER
15PCLPCHPROGRAM COUNTER
S1STACK POINTER
STATUS REGISTERC
CarryZ
ZeroIInterrupt DisableD
Decimal ModeB
BreakV
OverflowN
Negative
Source: Visual6502.org
Source: Visual6502.org
Source: Visual6502.org
6502 Instruction Encoding
groupmodeopcode groupmodeopcodeliteral or address groupmodeopcodelow address bytehigh address byte6502 Instruction Encoding
10modeopcode"Group one" add, compare; most addressing modes
01modeopcode"Group two" shift/rotate, load/store X; fewer modes
001modeopcodeLoad/store Y, compare X & Y
0xy01op1Index register instructions
00011flagFlag set/clear
00001vflagBranches
0op0op000Stack instructions
11Unused in the 6502
6502 Instruction Encoding
10modeopcode"Group one" add, compare; most addressing modes
01modeopcode"Group two" shift/rotate, load/store X; fewer modes
001modeopcodeLoad/store Y, compare X & Y
0xy01op1Index register instructions
00011flagFlag set/clear
00001vflagBranches
0op0op000Stack instructions
11Unused in the 6502
6502 Instruction Encoding
10modeopcode"Group one" add, compare; most addressing modes
01modeopcode"Group two" shift/rotate, load/store X; fewer modes
001modeopcodeLoad/store Y, compare X & Y
0xy01op1Index register instructions
00011flagFlag set/clear
00001vflagBranches
0op0op000Stack instructions
11Unused in the 6502
6502 Instruction Encoding
10modeopcode"Group one" add, compare; most addressing modes
01modeopcode"Group two" shift/rotate, load/store X; fewer modes
001modeopcodeLoad/store Y, compare X & Y
0xy01op1Index register instructions
00011flagFlag set/clear
00001vflagBranches
0op0op000Stack instructions
11Unused in the 6502
Group One Instructions10modeopcode
A9 42LDA#$42; LoadAccumulator Immediate A9LDA
A#$42 42Group One Instructions10modeopcode
A9 42LDA#$42; LoadAccumulator Immediate A9LDA
A#$42 42Group One Instructions10modeopcode
A9 42LDA#$42; LoadAccumulator Immediate 85 42STA$42; StoreAccumulator Zero Page 42STA$42 42$42Zero Page
Memory
Group One Instructions10modeopcode
A9 42LDA#$42; LoadAccumulator Immediate 85 42STA$42; StoreAccumulator Zero Page 42STA$42 42$42Zero Page
MemoryA
Group One Instructions10modeopcode
A9 42LDA#$42; LoadAccumulator Immediate 85 42STA$42; StoreAccumulator Zero Page 75 42ADC$42,X; Addwith Carry Zero Page Indexed by X $42,XADC
CZero Page
Memory$42,X
42A
Group One Instructions10modeopcode
A9 42LDA#$42; LoadAccumulator Immediate 85 42STA$42; StoreAccumulator Zero Page 75 42ADC$42,X; Addwith Carry Zero Page Indexed by X $42,XADC
C$42,X
42AX+ $42 + XZero Page
Memory
Group One Instructions10modeopcode
A9 42LDA#$42; LoadAccumulator Immediate 85 42STA$42; StoreAccumulator Zero Page 75 42ADC$42,X; Addwith Carry Zero Page Indexed by X ED 01 42SBC$4201; Subtractw /CarryAbsolute EDSBC
Memory$4201
0142A C
Group One Instructions10modeopcode
A9 42LDA#$42; LoadAccumulator Immediate 85 42STA$42; StoreAccumulator Zero Page 75 42ADC$42,X; Addwith Carry Zero Page Indexed by X ED 01 42SBC$4201; Subtractw /CarryAbsolute EDSBC
$4201Memory$4201 0142A C
Group One Instructions10modeopcode
A9 42LDA#$42; LoadAccumulator Immediate 85 42STA$42; StoreAccumulator Zero Page 75 42ADC$42,X; Addwith Carry Zero Page Indexed by X ED 01 42SBC$4201; Subtractw /CarryAbsolute DD 05 42CMP$4205,X; CompareAbsolute Indexed by X DDCMP
Memory$4205
0542A N Z C
Group One Instructions10modeopcode
A9 42LDA#$42; LoadAccumulator Immediate 85 42STA$42; StoreAccumulator Zero Page 75 42ADC$42,X; Addwith Carry Zero Page Indexed by X ED 01 42SBC$4201; Subtractw /CarryAbsolute DD 05 42CMP$4205,X; CompareAbsolute Indexed by X DDCMP
$4205 + XMemory$4205 0542A
N Z CX+
Group One Instructions10modeopcode
A9 42LDA#$42; LoadAccumulator Immediate 85 42STA$42; StoreAccumulator Zero Page 75 42ADC$42,X; Addwith Carry Zero Page Indexed by X ED 01 42SBC$4201; Subtractw /CarryAbsolute DD 05 42CMP$4205,X; CompareAbsolute Indexed by X 39 06 42AND$4206,Y; LogicalAND Absolute Indexed by Y 39AND
Memory$4206,Y
0642AAND
Group One Instructions10modeopcode
A9 42LDA#$42; LoadAccumulator Immediate 85 42STA$42; StoreAccumulator Zero Page 75 42ADC$42,X; Addwith Carry Zero Page Indexed by X ED 01 42SBC$4201; Subtractw /CarryAbsolute DD 05 42CMP$4205,X; CompareAbsolute Indexed by X 39 06 42AND$4206,Y; LogicalAND Absolute Indexed by Y 39AND
Y $4206 + YMemory+$4206,Y 0642AAND
Group One Instructions10modeopcode
A9 42LDA#$42; LoadAccumulator Immediate 85 42STA$42; StoreAccumulator Zero Page 75 42ADC$42,X; Addwith Carry Zero Page Indexed by X ED 01 42SBC$4201; Subtractw /CarryAbsolute DD 05 42CMP$4205,X; CompareAbsolute Indexed by X 39 06 42AND$4206,Y; LogicalAND Absolute Indexed by Y 11 42ORA($42),Y; LogicalOR Indirect Indexed 11ORA
OR($42),Y
42AMemory
Group One Instructions10modeopcode
A9 42LDA#$42; LoadAccumulator Immediate 85 42STA$42; StoreAccumulator Zero Page 75 42ADC$42,X; Addwith Carry Zero Page Indexed by X ED 01 42SBC$4201; Subtractw /CarryAbsolute DD 05 42CMP$4205,X; CompareAbsolute Indexed by X 39 06 42AND$4206,Y; LogicalAND Absolute Indexed by Y 11 42ORA($42),Y; LogicalOR Indirect Indexed 11ORA
$42 $43Zero PageMemoryOR($42),Y
42AMemory
Group One Instructions10modeopcode
A9 42LDA#$42; LoadAccumulator Immediate 85 42STA$42; StoreAccumulator Zero Page 75 42ADC$42,X; Addwith Carry Zero Page Indexed by X ED 01 42SBC$4201; Subtractw /CarryAbsolute DD 05 42CMP$4205,X; CompareAbsolute Indexed by X 39 06 42AND$4206,Y; LogicalAND Absolute Indexed by Y 11 42ORA($42),Y; LogicalOR Indirect Indexed 11ORA
$42 $43Zero PageMemoryOR($42),Y
42AY +Memory
Group One Instructions10modeopcode
A9 42LDA#$42; LoadAccumulator Immediate 85 42STA$42; StoreAccumulator Zero Page 75 42ADC$42,X; Addwith Carry Zero Page Indexed by X ED 01 42SBC$4201; Subtractw /CarryAbsolute DD 05 42CMP$4205,X; CompareAbsolute Indexed by X 39 06 42AND$4206,Y; LogicalAND Absolute Indexed by Y 11 42ORA($42),Y; LogicalOR Indirect Indexed 41 42EOR($42,X); ExclusiveOR Indexed Indirect 41EOR
Memory($42,X)
42XORA
Group One Instructions10modeopcode
A9 42LDA#$42; LoadAccumulator Immediate 85 42STA$42; StoreAccumulator Zero Page 75 42ADC$42,X; Addwith Carry Zero Page Indexed by X ED 01 42SBC$4201; Subtractw /CarryAbsolute DD 05 42CMP$4205,X; CompareAbsolute Indexed by X 39 06 42AND$4206,Y; LogicalAND Absolute Indexed by Y 11 42ORA($42),Y; LogicalOR Indirect Indexed 41 42EOR($42,X); ExclusiveOR Indexed Indirect 41EOR
X+ $42 + X $43 + XZero PageMemoryMemory($42,X)
42XORA
Group One Instructions10modeopcode
A9 42LDA#$42; LoadAccumulator Immediate 85 42STA$42; StoreAccumulator Zero Page 75 42ADC$42,X; Addwith Carry Zero Page Indexed by X ED 01 42SBC$4201; Subtractw /CarryAbsolute DD 05 42CMP$4205,X; CompareAbsolute Indexed by X 39 06 42AND$4206,Y; LogicalAND Absolute Indexed by Y 11 42ORA($42),Y; LogicalOR Indirect Indexed 41 42EOR($42,X); ExclusiveOR Indexed Indirect 41EOR
X+ $42 + X $43 + XZero PageMemoryMemory($42,X)
42XORA
Apple II Zero
Page UsageMonitorApplesoftDOS 3.3ProDOS
Source: comp.sys.apple2 FAQ, Wagner,
Wirth and Lechner0
01 12 2334
45
56
67
78
89
9A AB BC CD DE EF F
Apple II Zero
Page UsageMonitorApplesoftDOS 3.3ProDOS
Source: comp.sys.apple2 FAQ, Wagner,
Wirth and Lechner0
01 12 2334
45
56
67
78
89
9A AB BC CD DE EF F
Apple II Zero
Page UsageMonitorApplesoftDOS 3.3ProDOS
Source: comp.sys.apple2 FAQ, Wagner,
Wirth and Lechner0
01 12 2334
45
56
67
78
89
9A AB BC CD DE EF F
Group Two Instructions01modeopcode
A2 42LDX#$42; LoadX Immediate A2LDX
X#$42 42Group Two Instructions01modeopcode
A2 42LDX#$42; LoadX Immediate 86 42STX$42; StoreX Zero Page 86STX$42 42X$42Zero Page
Memory
Group Two Instructions01modeopcode
A2 42LDX#$42; LoadX Immediate 86 42STX$42; StoreX Zero Page F6 42INC$42,X; IncrementZero Page Indexed by X F6INC
1$42,X
42$42 + XZero Page
MemoryX+
Group Two Instructions01modeopcode
A2 42LDX#$42; LoadX Immediate 86 42STX$42; StoreX Zero Page F6 42INC$42,X; IncrementZero Page Indexed by X CE 77 42DEC$4277; DecrementAbsolute CEDEC
1$4277
7742$4277Memory
Group Two Instructions01modeopcode
A2 42LDX#$42; LoadX Immediate 86 42STX$42; StoreX Zero Page F6 42INC$42,X; IncrementZero Page Indexed by X CE 77 42DEC$4277; DecrementAbsolute 0AASL;ArithmeticShift Left Accumulator 0AASL
0CGroup Two Instructions01modeopcode
A2 42LDX#$42; LoadX Immediate 86 42STX$42; StoreX Zero Page F6 42INC$42,X; IncrementZero Page Indexed by X CE 77 42DEC$4277; DecrementAbsolute 0AASL;ArithmeticShift Left Accumulator 5E 80 42LSR$4280,X; LogicalShift Right Absolute Indexed by X 5ELSR$4280,X
80420C
Group Two Instructions01modeopcode
A2 42LDX#$42; LoadX Immediate 86 42STX$42; StoreX Zero Page F6 42INC$42,X; IncrementZero Page Indexed by X CE 77 42DEC$4277; DecrementAbsolute 0AASL;ArithmeticShift Left Accumulator 5E 80 42LSR$4280,X; LogicalShift Right Absolute Indexed by X 2AROL;RotateLeft Accumulator 2AROL
CGroup Two Instructions01modeopcode
A2 42LDX#$42; LoadX Immediate 86 42STX$42; StoreX Zero Page F6 42INC$42,X; IncrementZero Page Indexed by X CE 77 42DEC$4277; DecrementAbsolute 0AASL;ArithmeticShift Left Accumulator 5E 80 42LSR$4280,X; LogicalShift Right Absolute Indexed by X 2AROL;RotateLeft Accumulator 6AROR;RotateRight Accumulator 6AROR
COther Instructions001modeopcode
A0 42LDY#$42; LoadY Immediate 94 42STY$42,X; StoreY Zero Page Indexed by X C4 42CPY$42; CompareY Zero Page EC 50 42CPX$4250; CompareX Absolute
Other Instructions001modeopcode
A0 42LDY#$42; LoadY Immediate 94 42STY$42,X; StoreY Zero Page Indexed by X C4 42CPY$42; CompareY Zero Page EC 50 42CPX$4250; CompareX Absolute 4C 40 42JMP$4240; JumpAbsolute 4CJMP$4240
4042PCHPCL
Other Instructions001modeopcode
A0 42LDY#$42; LoadY Immediate 94 42STY$42,X; StoreY Zero Page Indexed by X C4 42CPY$42; CompareY Zero Page EC 50 42CPX$4250; CompareX Absolute 4C 40 42JMP$4240; JumpAbsolute 6C 41 42JMP($4241); JumpIndirect 6CJMP$4241
4142PCHPCL
$4241 $4242MemoryOther Instructions001modeopcode
A0 42LDY#$42; LoadY Immediate 94 42STY$42,X; StoreY Zero Page Indexed by X C4 42CPY$42; CompareY Zero Page EC 50 42CPX$4250; CompareX Absolute 4C 40 42JMP$4240; JumpAbsolute 6C 41 42JMP($4241); JumpIndirect 6CJMP$4241
4142PCHPCL
$4241 $4242MemoryOther Instructions001modeopcode
A0 42LDY#$42; LoadY Immediate 94 42STY$42,X; StoreY Zero Page Indexed by X C4 42CPY$42; CompareY Zero Page EC 50 42CPX$4250; CompareX Absolute 4C 40 42JMP$4240; JumpAbsolute 6C 41 42JMP($4241); JumpIndirect 2C 57 42BIT$4257; TestBits w /Accum .Absolute 2CBIT$4257
5742$4257Memory ($4257)^A!Z, ($4257)!N, V, -, -, -, -, -, - The byte at address $4257 is read and bits 7 and 6 are stored in flags N and V. The value is ANDed with the accumulator and the Z flag is set on a zero result The most bizarre of 6502 instructions:CMPwith logical AND instead of subtraction, but also stores the MSB and 6SB into N and V.
Other Instructions001modeopcode
A0 42LDY#$42; LoadY Immediate 94 42STY$42,X; StoreY Zero Page Indexed by X C4 42CPY$42; CompareY Zero Page EC 50 42CPX$4250; CompareX Absolute 4C 40 42JMP$4240; JumpAbsolute 6C 41 42JMP($4241); JumpIndirect 2C 57 42BIT$4257; TestBits w /Accum .Absolute 2CBIT$4257
5742$4257Memory Z N V
Other Instructions001modeopcode
A0 42LDY#$42; LoadY Immediate 94 42STY$42,X; StoreY Zero Page Indexed by X C4 42CPY$42; CompareY Zero Page EC 50 42CPX$4250; CompareX Absolute 4C 40 42JMP$4240; JumpAbsolute 6C 41 42JMP($4241); JumpIndirect 2C 57 42BIT$4257; TestBits w /Accum .Absolute 2CBIT$4257
5742ANDA$4257Memory
Z N VSingle-Byte Data Instructions0xy01op1
E8INX;IncrementX CADEX;DecrementX C8INY;IncrementY 88DEY;DecrementY AATAX;TransferAccumulator to X A8TAY;TransferAccumulator to Y 8ATXA;TransferX to Accumulator 98TYA;TransferY to Accumulator BATSX;TransferStack Pointer to X 9ATXS;TransferX to Stack Pointer
Single-Byte Flag Instructions00011flag
18CLC;ClearCarry Flag 38SEC;SetCarry Flag 58CLI;ClearInterrupt Disable 78SEI;SetInterrupt Disable B8CLV;ClearOverflow Flag Set and clear the carry flag; useful withADCandSBC
Enable and disable interrupts. Useful for critical regionsClear the overflow flag
Single-Byte Flag Instructions00011flag
18CLC;ClearCarry Flag 38SEC;SetCarry Flag 58CLI;ClearInterrupt Disable 78SEI;SetInterrupt Disable B8CLV;ClearOverflow Flag D8CLD;ClearDecimal Mode ( ADC,SBC perform binary arithmetic )F8SED;SetDecimal Mode ( ADC,SBC perform BCD arithemtic )In decimal mode,ADCandSBC
perform BCD arithmetic.In decimal mode, $19 + $1 = $20In binary mode, $19 + $1 = $1A
US Patent 3,991,307 (1976) describes the 6502"s decimal adjust logic The 6502-based Ricoh 2A03 used in the Famicom/Nintendo EntertainmentSystem does not support decimal mode
Branch Instructions00001vflag
10 FE STARTBPLSTART; Branchon Plus N =030 0ABMIEND; Branchon Minus N =150 FABVCSTART; Branchon Overflow Clear V =070 06BVSEND; Branchon Overflow Set V =190 F6BCCSTART; Branchon Carry Clear C =0B0 02BCSEND; Branchon Carry Set C =1D0 F2BNESTART; Branchon Not Equal Z =0F0 FE ENDBEQEND; Branchon Equal Z =1Conditionally branch depending on the state of one of the four flags
Branch destination is program-counter-relative: between128 and 127 bytesUseJMPto branch farther
BNEandBEQcould be called "branch on non-zero" and "branch on zero"The 65C02 added the unconditionalBRAinstruction
Stack Instructions0op0op000
20 ED FDJSR$FDED; Jumpto Subroutine 60RTS;Returnfrom Subroutine For subroutine linkage:
JSR$FDED pushes the program counter onto the stack then jumps to $FDED RTSpops the program counter value off the stack, returning to just after theJSRthat sent it there
Stack Instructions0op0op000
20 ED FDJSR$FDED; Jumpto Subroutine 60RTS;Returnfrom Subroutine 40RTI;Returnfrom Interrupt Return from an interrupt by popping the status register and the program
counter from the stack. (LikeRTS, but also restores the status register) Useful in interrupt routines and returning fromBRKStack Instructions0op0op000
20 ED FDJSR$FDED; Jumpto Subroutine 60RTS;Returnfrom Subroutine 40RTI;Returnfrom Interrupt 08PHP;PushProcessor Status 28PLP;PullProcessor Status 48PHA;PushAccumulator 68PLA;PullAccumulator Save and restore the processor status on the stack
Save and restore the accumulator on the stack
Typical processors encourage functions to save registers on the stack, but the6502"s cramped (256 byte) stack demands parsimony
Stack Instructions0op0op000
20 ED FDJSR$FDED; Jumpto Subroutine 60RTS;Returnfrom Subroutine 40RTI;Returnfrom Interrupt 08PHP;PushProcessor Status 28PLP;PullProcessor Status 48PHA;PushAccumulator 68PLA;PullAccumulator 00BRK;BreakEANOP;Nooperation BRKis a software interrupt that pushes the current program counter and
status register on the stack before jumping to the break vector stored (inROM) at $FFFE.
NOPdoes nothing for two cycles. Useful in delay loops or to patch a program in memory.Hello World in 6502 Assembly
ORG $8000
Set code originCOUT EQU $FDED
Define
COUT label character outENTRYLDX#0; Use X because COUT leaves it unchanged LOOPLDAMSG,X; Get character from string BEQDONE; Are we at the end ?JSRCOUT; No :print the character INX;Go to next character in string BNELOOP; A trick :always taken DONERTS;Return MSG ASC "Hello World!"; Generate ASCII character code s