[PDF] Programming the 65816 6502/65C02 Addressing Modes on





Previous PDF Next PDF



6502 Assembly Language Subroutines

For information on translations and book distributors outside of the U.S.A. please write OSBORNE/. McGraw-Hill at the above address. 6502 ASSEMBLY LANGUAGE 



Advanced 6502 Assembly Language Programming on the Apple //e

A9 42. LDA #$42. ;Load Accumulator. Immediate. 85 42. STA $42. ;Store Accumulator. Zero Page. 75 42. ADC $42X. ;Add with Carry. Zero Page Indexed by X.



Nerdy-Nights-NES-Tutorials-v1.pdf

The assembly language for 6502 starts with a 3 character code for the instruction "opcode". There are 56 instructions 10 of which you will use frequently. Many 



6502 Stack

20 sept. 2019 POKE 10241 writes letter A into top left corner. – PRINT PEEK(1024) returns 1. Philipp Koehn. Computer Systems Fundamentals: 6502 Stack.



Merlin 8/16 - The Complete Macro Assembler System For the Apple

9 févr. 1989 A tutorial on assembly language programming designed specifically for the novice. It gives a description of all 6502 instructions disk access



Langage Assembleur PC

4 déc. 2021 si vous voulez assembler et exécuter la plupart des exemples de ce tutorial. Soyez conscient que ce texte ne tente pas de couvrir tous les ...



Programming the 65816

6502/65C02 Addressing Modes on the 65816. The Same Example Hand-Coded in Assembly Language . ... The Western Design Center. 63. Part 3. Tutorial ...



Apple IIe Users Handbook

The Apple lie User's Handbook is meant to serve as a tutorial as PASCAL FORTRAN



MADMAC 68000 Macro Assembler Reference Manual

Macro Declaration. Parameter Substitution. Macro Invocation. Example Macros. Repeat Blocks. 6502 Addressing Modes. 6502 Directives. 6502 Object Code Format.



Technical Reference Manual 2.20.15

29 août 2020 Clarified the difference in usage of brackets on F8/6502 ... It explains how to use dasm and the supported assembler directives. 1.2 Home.

Programming the 65816

Including the 6502, 65C02 and 65802

Distributed and published under

COPYRIGHT LICENSE AND PUBLISHING AGREEMENT

with

Authors David Eyes and Ron Lichty

EFFECTIVE APRIL 28, 1992

Copyright © 2007 by The Western Design Center, Inc.

2166 E. Brown Rd. Mesa, AZ 85213

480-962-4545 (p) 480-835-6442 (f)

www.westerndesigncenter.com

The Western Design Center

2

Table of Contents

1)Chapter One..........................................................................................................12

Basic Assembly Language Programming Concepts..................................................................................12

Binary Numbers....................................................................................................................................................12

Grouping Bits into Bytes.......................................................................................................................................13

Hexadecimal Representation of Binary................................................................................................................14

The ACSII Character Set.....................................................................................................................................15

Boolean Logic........................................................................................................................................................16

Logical And........................................................................................................................................................16

Logical Or..........................................................................................................................................................17

Logical Exclusive Or...........................................................................................................................................17

Logical Complement...........................................................................................................................................17

Signed Numbers....................................................................................................................................................18

Storing Numbers in Decimal Form.......................................................................................................................19

Computer Arithmetic............................................................................................................................................20

Microprocessor Programming..............................................................................................................................20

Machine Language..............................................................................................................................................20

Assembly Language............................................................................................................................................22

Writing in Assembly Language............................................................................................................................22

Basic Programming Concepts...............................................................................................................................23

Selection Between Paths......................................................................................................................................24

2)Chapter Two..........................................................................................................26

Architecture of the 6502............................................................................................................................26

Microprocessor Architecture................................................................................................................................26

The 6502 Registers................................................................................................................................................26

The Accumulator................................................................................................................................................27

The X and Y Index Registers...............................................................................................................................29

The Status Register.............................................................................................................................................29

The Stack Pointer................................................................................................................................................31

The Program Counter..........................................................................................................................................33

Addressing Modes.................................................................................................................................................33

The 6502 System Design........................................................................................................................................38

Memory Order of Multiple-Byte Values..............................................................................................................39

Memory-Mapped Input/Output............................................................................................................................39

NMOS Process......................................................................................................................................................40

Bugs and Quirks...................................................................................................................................................40

3)Chapter Three.......................................................................................................41

Architecture of the 65C02.........................................................................................................................41

The 65C02 Architecture........................................................................................................................................41

Addressing Modes.................................................................................................................................................41

CMOS Process......................................................................................................................................................42

Bugs and Quirks...................................................................................................................................................42

4)Chapter Four.........................................................................................................44

Sixteen-Bit Architecture The 65816 and the 65802...................................................................................44

The Western Design Center

3

Power-On Status: 6502 Emulation Mode..................................................................................................45

The Full-Featured 65x Processor: The 65816 in Native Mode................................................................45

The Program Bank Register.................................................................................................................................47

The Data Bank Register........................................................................................................................................48

The Direct Page Register......................................................................................................................................48

The Stack Pointer..................................................................................................................................................48

Accumulator and Index Registers........................................................................................................................48

Switching Registers Between Eight and Sixteen Bits............................................................................................50

The Status Register...............................................................................................................................................50

6502/65C02 Addressing Modes on the 65816........................................................................................................51

New 65816 Addressing Modes..............................................................................................................................52

The 65802 Native Mode.............................................................................................................................55

Emulation Mode....................................................................................................................................................58

Emulation Mode Registers....................................................................................................................................60

Switching Between 6502 Emulation and Native Modes............................................................................61

Switching from Emulation to Native Mode..........................................................................................................61

Switching from Native to Emulation Mode..........................................................................................................61

65802/65816 Bugs and Quirks...................................................................................................................62

5)Chapter Five..........................................................................................................64

SEP, REP, and Other Details....................................................................................................................64

The Assembler Used in This Book........................................................................................................................66

Address Notation...................................................................................................................................................68

6)Chapter Six............................................................................................................69

First Examples: Moving Data....................................................................................................................69

Loading and Storing Registers.............................................................................................................................71

Effect of Load and Store Operations on Status Flags............................................................................................73

Moving Data Using the Stack..............................................................................................................................73

Pushing the Basic 65x Registers..........................................................................................................................76

Pulling the Basic 65x Registers...........................................................................................................................76

Pushing and Pulling the 65816's Additional Registers..........................................................................................78

Pushing Effective Addresses................................................................................................................................79

Other Attributes of Push and Pull........................................................................................................................79

Moving Data Between Registers...........................................................................................................................79

Storing Zero to Memory.......................................................................................................................................86

Block Moves..........................................................................................................................................................87

7)Chapter Seven.......................................................................................................89

SimpleAddressing Modes..........................................................................................................................89

Immediate Addressing..........................................................................................................................................90

Absolute Addressing.............................................................................................................................................92

Direct Page Addressing.........................................................................................................................................94

Absolute Indexed with X and Absolute Indexed with Y Addressing...................................................................98

Direct Page Indexed with X and Direct Page Indexed with Y Addressing........................................................101

Accumulator Addressing....................................................................................................................................103

Implied Addressing.............................................................................................................................................103

Direct Page Indirect Addressing.........................................................................................................................104

Absolute Long Addressing..................................................................................................................................105

The Western Design Center

4

Absolute Long Indexed with X Addressing........................................................................................................108

Direct Page Indirect Long...................................................................................................................................109

Block Move..........................................................................................................................................................110

8)Chapter Eight......................................................................................................111

The Flow of Control.................................................................................................................................111

Jump Instructions...............................................................................................................................................112

Conditional Branching........................................................................................................................................114

Branching Based on the Zero Flag.....................................................................................................................115

Branching Based on the Carry Flag...................................................................................................................117

Branching Based on the Negative Flag..............................................................................................................118

Branching Based on the Overflow Flag..............................................................................................................119

Limitations of Conditional Branches..................................................................................................................119

Unconditional Branching....................................................................................................................................119

9)Chapter Nine.......................................................................................................122

Built-In Arithmetic Functions.................................................................................................................122

Increment and Decrement..................................................................................................................................123

Addition and Subtraction: Unsigned Arithmetic..............................................................................................127

Signed Arithmetic...............................................................................................................................................134

Signed Comparisons............................................................................................................................................136

Decimal Mode.....................................................................................................................................................137

10)Chapter Ten......................................................................................................139

Logic and Bit Manipulation Operations.................................................................................................139

Logic Functions...................................................................................................................................................139

Logical AND....................................................................................................................................................140

Logical OR.......................................................................................................................................................142

Logical Exclusive-Or........................................................................................................................................143

Bit Manipulation.................................................................................................................................................145

Shifts and Rotates...............................................................................................................................................146

11)Chapter Eleven.................................................................................................154

The Complex Addressing Modes.............................................................................................................154

Relocating the Direct Page..................................................................................................................................155

Assembler Addressing Mode Assumptions.........................................................................................................156

Direct Page Indirect Indexed With Y Addressing..............................................................................................158

Direct Page Indexing Indirect Addressing.........................................................................................................161

Absolute Indexed Indirect Addressing...............................................................................................................163

Direct Page Indirect Long Indexed with Y Addressing......................................................................................165

Stack Relative Addressing..................................................................................................................................166

Stack Relative Indirect Indexed Addressing......................................................................................................168

Push Effective Instructions.................................................................................................................................169

12)Chapter Twelve.................................................................................................174

The Basic Building Block:.......................................................................................................................174

The Subroutine....................................................................................................................................................174

The Jump-To-Subroutine Instruction................................................................................................................175

The Return-from-Subroutine Instruction..........................................................................................................175

JRS Using Absolute Indexed Indirect Addressing.............................................................................................177

The Long Jump to Subroutine............................................................................................................................178

Return from Subroutine Long............................................................................................................................178

Branch to Subroutine..........................................................................................................................................179

Coding a Subroutine: How and When................................................................................................................180

6502 Eight-Bit Negation - A Library Example..................................................................................................180

65C02, 65802, and 65816 Eight-Bit Negation....................................................................................................181

The Western Design Center

5

6502 Sixteen-Bit Negation................................................................................................................................181

65802 and 65816 Sixteen-Bit Negation..............................................................................................................181

Parameter Passing..............................................................................................................................................182

13)Chapter Thirteen..............................................................................................192

Interrupts and System Control Instructions...........................................................................................192

Processing Interrupts.........................................................................................................................................197

Interrupt Response Time...................................................................................................................................200

Status Register Control Instruction....................................................................................................................201

No Operation Instructions..................................................................................................................................202

14)Chapter Fourteen.............................................................................................204

Selected Code Samples.............................................................................................................................204

6502 Multiplication...........................................................................................................................................205

65C02 Multiplication........................................................................................................................................205

65802 and 65816 Multiplication........................................................................................................................205

6502 Division...................................................................................................................................................209

65C02 Division.................................................................................................................................................211

65802/65816 Division.......................................................................................................................................211

Calling an Arbitrary 6502 Routine.....................................................................................................................213

Testing Processor Type.......................................................................................................................................219

Compiler-Generated 65816 Code for a RecursiveProgram...............................................................................220

The Same Example Hand-Coded in Assembly Language...................................................................................224

The Sieve of Eratosthenes Benchmark...............................................................................................................226

15)Chapter Fifteen................................................................................................230

DEGUG16 - A 65816 Programming Tool...............................................................................................230

16)Chapter Sixteen................................................................................................276

Design and Debugging.............................................................................................................................276

Debugging Checklist...........................................................................................................................................276

Decimal Flag....................................................................................................................................................276

Adjusting Carry Prior to Add / Subtract.............................................................................................................276

65x Left-to-Right Syntax...................................................................................................................................276

65x Branches....................................................................................................................................................277

6502 Jump Bug.................................................................................................................................................277

Interrupt-Handling Code....................................................................................................................................277

65802/65816: Emulation Versus Native Mode...................................................................................................277

65802/65816: Eight-Bit Versus Sixteen-Bit Registers........................................................................................278

65802/65816: The Direct Page..........................................................................................................................278

The Western Design Center

6

65802/65816: Stack Overruns Program or Data.................................................................................................278

65802/65816: JSR/JSL and RTS/RTL................................................................................................................278

65802/65816: MVN/MVP.................................................................................................................................278

Return Address.................................................................................................................................................279

Inconsistent Assembler Syntax..........................................................................................................................279

Generic Bugs: They Can Happen Anywhere......................................................................................................279

Uninitialized Variables......................................................................................................................................279

Missing Code....................................................................................................................................................279

Failure to Increment the Index in a Loop............................................................................................................279

Failure to Clean Up Stack..................................................................................................................................280

Immediate Data Versus Memory Location.........................................................................................................280

Initializing the Stack Pointer from a Subroutine.................................................................................................280

Top-Down Design and Structured Programming..............................................................................................280

17)Chapter Seventeen............................................................................................283

The Addressing Modes............................................................................................................................283

Absolute Addressing.........................................................................................................................................288

Absolute Indexed, X Addressing.......................................................................................................................289

Absolute Indexed, Y Addressing.......................................................................................................................290

Absolute Indexed Indirect Addressing...............................................................................................................291

Absolute Indirect Addressing............................................................................................................................292

Absolute Indirect Long Addressing...................................................................................................................293

JMP [addr]........................................................................................................................................................293

Absolute Long Addressing................................................................................................................................294

Absolute Long Indexed, X Addressing..............................................................................................................295

Accumulator Addressing...................................................................................................................................296

Block Move Addressing....................................................................................................................................297

Direct Page Addressing.....................................................................................................................................298

Direct Page Indexed, X Addressing...................................................................................................................299

Direct Page Indexed, Y Addressing...................................................................................................................300

Direct Page Indexed Indirect, X Addressing.......................................................................................................301

Direct Page Indirect Addressing........................................................................................................................302

Direct Page Indirect Long Addressing...............................................................................................................303

Direct Page Indirect Indexed, Y Addressing.......................................................................................................304

Direct Page Indirect Long Indexed, Y Addressing..............................................................................................305

Immediate Addressing.......................................................................................................................................306

Implied Addressing...........................................................................................................................................307

Program Counter Relative Addressing...............................................................................................................308

Program Counter Relative Long Address...........................................................................................................309

Stack (Absolute) Addressing.............................................................................................................................310

Stack (Direct Page Indirect) Addressing............................................................................................................312

Stack (Interrupt) Addressing..............................................................................................................................314

Stack (Program Counter Relative) Addressing...................................................................................................316

Stack (Pull) Addressing.....................................................................................................................................317

Stack (Push) Addressing....................................................................................................................................319

Stack (RTI) Addressing.....................................................................................................................................321

Stack (RTL) Addressing....................................................................................................................................322

Stack (RTS) Addressing....................................................................................................................................323

Stack Relative Addressing.................................................................................................................................324

Stack Relative Indirect Indexed, Y Addressing..................................................................................................325

18)Chapter Eighteen..............................................................................................326

The Instruction Sets.................................................................................................................................326

Add With Carry..................................................................................................................................................327

And Accumulator with Memory.........................................................................................................................328

The Western Design Center

7

Shift Memory or Accumulator Left....................................................................................................................329

Branch if Carry Clear.........................................................................................................................................330

Branch if Carry Set.............................................................................................................................................331

Branch if Equal...................................................................................................................................................332

Test Memory Bits against Accumulator.............................................................................................................333

Branch if Minus..................................................................................................................................................334

Branch if Not Equal............................................................................................................................................335

Branch if Plus......................................................................................................................................................336

Branch Always....................................................................................................................................................337

Software Break...................................................................................................................................................338

Branch Always Long...........................................................................................................................................340

Branch if Overflow Clear...................................................................................................................................341

Branch if Overflow Set.......................................................................................................................................342

Clear Carry Flag.................................................................................................................................................343

Clear Decimal Mode Flag...................................................................................................................................344

Clear Interrupt Disable Flag..............................................................................................................................345

Clear Overflow Flag............................................................................................................................................346

Compare Accumulator with Memory.................................................................................................................347

Co-Processor Enable...........................................................................................................................................349

Compare Index Register X with Memory...........................................................................................................350

Compare Index Register Y with Memory CPY..................................................................................................351

Decrement Index Register X...............................................................................................................................353

Decrement Index Register Y...............................................................................................................................354

Exclusive-OR Accumulator with Memory.........................................................................................................355

Increment Index Register X................................................................................................................................358

Increment Index Register Y................................................................................................................................359

Jump to Subroutine Long (Inter-Bank).............................................................................................................361

Jump to Subroutine.............................................................................................................................................362

Load Accumulator from Memory.......................................................................................................................363

Load Index Register X from Memory................................................................................................................364

Load Index Register Y from Memory................................................................................................................365

Logical Shift Memory or Accumulator Right.....................................................................................................366

Block Move Next.................................................................................................................................................367

Block Move Previous...........................................................................................................................................368

No Operation.......................................................................................................................................................369

OR Accumulator with Memory..........................................................................................................................370

Push Effective Absolute Address........................................................................................................................372

Push Effective Indirect Address.........................................................................................................................373

Push Effective PC Relative Indirect Address.....................................................................................................374

Push Accumulator...............................................................................................................................................375

Push Data Bank Register....................................................................................................................................376

Push Direct Page Register...................................................................................................................................377

Push Program Bank Register.............................................................................................................................378

Push Processor Status Register...........................................................................................................................379

Push Index Register............................................................................................................................................380

Push Index Register............................................................................................................................................381

Pull Accumulator................................................................................................................................................382

Pull Data Bank Register......................................................................................................................................383

Pull Direct Page Register....................................................................................................................................384

Pull Status Flags..................................................................................................................................................385

Pull Index Register X from Stack.......................................................................................................................386

Pull Index Register Y from Stack.......................................................................................................................387

Reset Status Bits..................................................................................................................................................388

Rotate Memory or Accumulator Left.................................................................................................................389

The Western Design Center

8

Rotate Memory or Accumulator Right...............................................................................................................390

Return from Interrupt........................................................................................................................................391

Return from Subroutine Long............................................................................................................................393

Return from Subroutine.....................................................................................................................................394

Subtract with Borrow from Accumulator..........................................................................................................395

Set Carry Flag.....................................................................................................................................................397

Set Decimal Mode Flag.......................................................................................................................................398

Set Interrupt Disable Flag..................................................................................................................................399

Set Status Bits.....................................................................................................................................................400

Store Accumulator to Memory...........................................................................................................................401

Stop the Processor...............................................................................................................................................402

Store Index Register X to Memory.....................................................................................................................403

Store Index Register Y to Memory.....................................................................................................................404

Store Zero to Memory.........................................................................................................................................405

Transfer Accumulator to Index Register X........................................................................................................406

Transfer Accumulator to Index Register Y........................................................................................................407

Transfer 16-Bit Accumulator to Direct Page Register.......................................................................................408

Transfer Accumulator to Stack Pointer.............................................................................................................409

Transfer Direct Page Register to 16-Bit Accumulator.......................................................................................410

Test and Reset Memory Bits Against Accumulator............................................................................................411

Test and Set Memory Bits Against Accumulator...............................................................................................412

Transfer Stack Pointer to 16-Bit Accumulator...................................................................................................413

Transfer Stack Pointer to Index Register X.......................................................................................................414

Transfer Index Register X to Accumulator........................................................................................................415

Transfer Index Register X to Stack Pointer.......................................................................................................416

Transfer Index Register X to Y..........................................................................................................................417

Transfer Index Register Y to Accumulator........................................................................................................418

Transfer Index register Y to X............................................................................................................................419

Wait for Interrupt...............................................................................................................................................420

Reserved for Future Expansion..........................................................................................................................421

quotesdbs_dbs21.pdfusesText_27
[PDF] 6502 asr

[PDF] alcpt test pdf

[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

[PDF] 6502 brk bug

[PDF] 6502 brk opcode

[PDF] 6502 brk vector