/[projet1]/public/pc/tools/osdk/main/Osdk/_final_/documentation/doc_6502_instruction.htm
Defence Force logotype

Contents of /public/pc/tools/osdk/main/Osdk/_final_/documentation/doc_6502_instruction.htm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 70 - (show annotations)
Sun May 24 19:53:20 2009 UTC (10 years, 6 months ago) by dbug
File MIME type: text/html
File size: 16071 byte(s)
Added the complete source code of the OSDK.
Projects files are available for Visual Studio 6 and .net, plus a Code::Blocks setup (everything works except PictConv that relies on FreeImage - which does not build correctly on mingw)
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
2
3 <HTML lang=fr dir=ltr>
4 <HEAD>
5 <meta name="robots" content="noindex">
6 <meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
7 <title>OSDK - 6502 instruction set</title>
8 <link href="documentation.css" rel="stylesheet" type="text/css">
9 </HEAD>
10
11 <BODY>
12
13 <hr>
14 <A href="documentation.htm"><img src="arrow_back.gif"></A>
15 <img src="pics/osdk_logo_small.png">
16 <hr>
17
18 <h1>6502 instruction set</h1>
19
20 <p id=chapter>The 6502 instruction set</p>
21
22
23 <p>For each instruction is given the mnemonic, the description of what does the instruction, a
24 symbolic description of what the instruction is doing, the affected status flag, and finaly
25 the various adressing mode available for that instruction with the corresponding opcode.
26 </p>
27
28 <p>Symbols:
29 </p>
30
31 <ul>
32 <li>A - Accumulator</li>
33 <li>C - Carry flag</li>
34 <li>D - Decimal mode flag</li>
35 <li>I - Interupt flag</li>
36 <li>M - Memory</li>
37 <li>X - X index register</li>
38 <li>Y - Y index register</li>
39 <li>V - Overflow flag</li>
40 <li>Z - Zero flag</li>
41 </ul>
42
43
44 <p id=opcodename>ADC</p>
45 <span id=opcodedescription>Add to Accumulator with Carry</span><br>
46 <span id=opcodeaction>A+M+C -> A,C</span><br>
47 <span id=opcodeflags>N, Z, C, V</span><br>
48
49 <ul>
50 <li>$69 - ADC #aa </li>
51 <li>$65 - ADC aa </li>
52 <li>$75 - ADC aa,X </li>
53 <li>$6D - ADC aaaa </li>
54 <li>$7D - ADC aaaa,X </li>
55 </ul>
56
57
58 <p id=opcodename>AND</p>
59 <span id=opcodedescription>AND Memory with Accumulator</span><br>
60 <span id=opcodeaction>A and M -> A</span><br>
61 <span id=opcodeflags>N, Z</span><br>
62
63 <ul>
64 <li>$29 - AND #aa </li>
65 <li>$25 - AND aa </li>
66 <li>$35 - AND aa,X </li>
67 <li>$2D - AND aaaa </li>
68 <li>$3D - AND aaaa,X </li>
69 <li>$39 - AND aaaa,Y </li>
70 <li>$21 - AND (aa,X) </li>
71 <li>$31 - AND (aa),Y</li>
72 </ul>
73
74
75 <p id=opcodename>ASL</p>
76 <span id=opcodedescription>Arithmetic Shift Left</span><br>
77
78 <pre>
79 +-+-+-+-+-+-+-+-+
80 C <- |7|6|5|4|3|2|1|0| <- 0
81 +-+-+-+-+-+-+-+-+</pre>
82
83 <span id=opcodeflags>N, Z, C</span><br>
84
85 <ul>
86 <li>$0A - ASL A </li>
87 <li>$06 - ASL aa </li>
88 <li>$16 - ASL aa,X </li>
89 <li>$0E - ASL aaaa </li>
90 <li>$1E - ASL aaaa,X </li>
91 </ul>
92
93
94 <p id=opcodename>BCC</p>
95 <span id=opcodedescription>Branch on Carry Clear</span><br>
96 <span id=opcodeaction>branch on C=0</span><br>
97 <span id=opcodeflags>no flags</span><br>
98
99 <ul>
100 <li>$90 - BCC aa </li>
101 </ul>
102
103
104 <p id=opcodename>BCS</p>
105 <span id=opcodedescription>Branch on Carry Set</span><br>
106 <span id=opcodeaction>branch on C=1</span><br>
107 <span id=opcodeflags>no flags</span><br>
108
109 <ul>
110 <li>$B0 - BCS aa </li>
111 </ul>
112
113
114 <p id=opcodename>BEQ</p>
115 <span id=opcodedescription>Branch Zero Set</span><br>
116 <span id=opcodeaction>branch on Z=1</span><br>
117 <span id=opcodeflags>no flags</span><br>
118
119 <ul>
120 <li>$F0 - BEQ aa </li>
121 </ul>
122
123
124 <p id=opcodename>BIT</p>
125 <span id=opcodedescription>Test Bits in Memory with Accumulator</span><br>
126 <span id=opcodeaction>A and M, M7 -> N, M6 -> V (neither A nor M are altered)</span><br>
127 <span id=opcodeflags>N=M7, V=M6, Z=1 if A and M = 0</span><br>
128
129 <ul>
130 <li>$24 - BIT aa </li>
131 <li>$2C - BIT aaaa </li>
132 </ul>
133
134
135 <p id=opcodename>BMI</p>
136 <span id=opcodedescription>Branch on Result Minus</span><br>
137 <span id=opcodeaction>branch on N=1</span><br>
138 <span id=opcodeflags>no flags</span><br>
139
140 <ul>
141 <li>$30 - BMI aa </li>
142 </ul>
143
144
145 <p id=opcodename>BNE</p>
146 <span id=opcodedescription>Branch on Z reset</span><br>
147 <span id=opcodeaction>branch on Z=0</span><br>
148 <span id=opcodeflags>no flags</span><br>
149
150 <ul>
151 <li>$D0 - BNE aa </li>
152 </ul>
153
154
155 <p id=opcodename>BPL</p>
156 <span id=opcodedescription>Branch on Result Plus</span><br>
157 <span id=opcodeaction>branch on N=0</span><br>
158 <span id=opcodeflags>no flags</span><br>
159
160 <ul>
161 <li>$10 - BPL aa </li>
162 </ul>
163
164
165 <p id=opcodename>BRK</p>
166 <span id=opcodedescription>Force a Break</span><br>
167 <span id=opcodeaction>forced interrupt</span><br>
168 <span id=opcodeflags>B=1, I=1</span><br>
169
170 <ul>
171 <li>$00 - BRK </li>
172 </ul>
173
174
175 <p id=opcodename>BVC</p>
176 <span id=opcodedescription>Branch on Overflow Clear</span><br>
177 <span id=opcodeaction>branch on V=0</span><br>
178 <span id=opcodeflags>no flags</span><br>
179
180 <ul>
181 <li>$50 - BVC aa</li>
182 </ul>
183
184
185 <p id=opcodename>BVS</p>
186 <span id=opcodedescription>Branch on Overflow Set</span><br>
187 <span id=opcodeaction>branch on V=1</span><br>
188 <span id=opcodeflags> no flags</span><br>
189
190 <ul>
191 <li>$70 - BVS aa</li>
192 </ul>
193
194
195 <p id=opcodename>CLC</p>
196 <span id=opcodedescription>Clear Carry Flag</span><br>
197 <span id=opcodeaction>0 -> C</span><br>
198 <span id=opcodeflags> C=0</span><br>
199
200 <ul>
201 <li>$18 - CLC</li>
202 </ul>
203
204
205
206 <p id=opcodename>CLD</p>
207 <span id=opcodedescription>Clear Decimal Mode</span><br>
208 <span id=opcodeaction>0 -> D</span><br>
209 <span id=opcodeflags> D=0</span><br>
210
211 <ul>
212 <li>$D8 - CLD</li>
213 </ul>
214
215
216 <p id=opcodename>CLI</p>
217 <span id=opcodedescription>Clear Interrupt Disable</span><br>
218 <span id=opcodeaction>0 -> I</span><br>
219 <span id=opcodeflags> I=0</span><br>
220
221 <ul>
222 <li>$58 - CLI</li>
223 </ul>
224
225
226
227 <p id=opcodename>CLV</p>
228 <span id=opcodedescription>Clear Overflow Flag</span><br>
229 <span id=opcodeaction>0 -> V</span><br>
230 <span id=opcodeflags> V=0</span><br>
231
232 <ul>
233 <li>$B8 - CLV</li>
234 </ul>
235
236
237 <p id=opcodename>CMP</p>
238 <span id=opcodedescription>Compare Memory and Accumulator</span><br>
239 <span id=opcodeaction>A compared with M</span><br>
240 <span id=opcodeflags>A, X, or Y < Memory ---> N=1, Z=0, C=0</span><br>
241
242 <ul>
243 <li>$C9 - CMP #aa </li>
244 <li>$C5 - CMP aa </li>
245 <li>$D5 - CMP aa,X </li>
246 <li>$CD - CMP aaaa </li>
247 <li>$DD - CMP aaaa,X </li>
248 <li>$D9 - CMP aaaa,Y </li>
249 <li>$C1 - CMP (aa,X) </li>
250 <li>$D1 - CMP (aa),Y </li>
251 </ul>
252
253
254 <p id=opcodename>CPX</p>
255 <span id=opcodedescription>Compare Memory and X register</span><br>
256 <span id=opcodeaction>X compared with M</span><br>
257 <span id=opcodeflags>A, X, or Y < Memory ---> N=1, Z=0, C=0</span><br>
258
259 <ul>
260 <li>$E0 - CPX #aa </li>
261 <li>$E4 - CPX aa </li>
262 <li>$EC - CPX aaaa </li>
263 </ul>
264
265
266 <p id=opcodename>CPY</p>
267 <span id=opcodedescription>Compare Memory and Y register</span><br>
268 <span id=opcodeaction>Y compare with M</span><br>
269 <span id=opcodeflags>A, X, or Y < Memory ---> N=1, Z=0, C=0</span><br>
270
271 <ul>
272 <li>$C0 - CPY #aa </li>
273 <li>$C4 - CPY aa </li>
274 <li>$CC - CPY aaaa </li>
275 </ul>
276
277
278
279 <p id=opcodename>DEC</p>
280 <span id=opcodedescription>Decrement Memory by One</span><br>
281 <span id=opcodeaction>M - 1 -> M</span><br>
282 <span id=opcodeflags> N, Z</span><br>
283
284 <ul>
285 <li>$C6 - DEC aa </li>
286 <li>$D6 - DEC aa,X </li>
287 <li>$CE - DEC aaaa </li>
288 <li>$DE - DEC aaaa,X </li>
289 </ul>
290
291
292
293 <p id=opcodename>DEX</p>
294 <span id=opcodedescription>Decrement X</span><br>
295 <span id=opcodeaction>X - 1 -> X</span><br>
296 <span id=opcodeflags> N, Z</span><br>
297
298 <ul>
299 <li>$CA - DEX </li>
300 </ul>
301
302
303
304 <p id=opcodename>DEY</p>
305 <span id=opcodedescription>Decrement Y</span><br>
306 <span id=opcodeaction>Y - 1 -> Y</span><br>
307 <span id=opcodeflags> N, Z</span><br>
308
309 <ul>
310 <li>$88 - DEY </li>
311 </ul>
312
313
314
315
316 <p id=opcodename>EOR</p>
317 <span id=opcodedescription>Exclusive-OR Memory with Accumulator</span><br>
318 <span id=opcodeaction>A xor M -> A</span><br>
319 <span id=opcodeflags> N, Z</span><br>
320
321 <ul>
322 <li>$49 - EOR #aa </li>
323 <li>$45 - EOR $aa </li>
324 <li>$55 - EOR $aa,X </li>
325 <li>$4D - EOR $aaaa </li>
326 <li>$5D - EOR $aaaa,X </li>
327 <li>$59 - EOR $aaaa,Y </li>
328 <li>$41 - EOR ($aa,X) </li>
329 <li>$51 - EOR ($aa),Y </li>
330 </ul>
331
332
333
334 <p id=opcodename>INC</p>
335 <span id=opcodedescription>Increment Memory by one</span><br>
336 <span id=opcodeaction>M + 1 -> M </span><br>
337 <span id=opcodeflags> N, Z</span><br>
338
339 <ul>
340 <li>$E6 - INC $aa </li>
341 <li>$F6 - INC $aa,X </li>
342 <li>$EE - INC $aaaa </li>
343 <li>$FE - INC $aaaa,X </li>
344 </ul>
345
346
347
348 <p id=opcodename>INX</p>
349 <span id=opcodedescription>Increment X by one</span><br>
350 <span id=opcodeaction>X + 1 -> X </span><br>
351 <span id=opcodeflags> N, Z</span><br>
352
353 <ul>
354 <li>$E8 - INX </li>
355 </ul>
356
357
358
359 <p id=opcodename>INY</p>
360 <span id=opcodedescription>Increment Y by one</span><br>
361 <span id=opcodeaction>Y + 1 -> Y </span><br>
362 <span id=opcodeflags> N, Z</span><br>
363
364 <ul>
365 <li>$C8 - INY </li>
366 </ul>
367
368
369
370 <p id=opcodename>JMP</p>
371 <span id=opcodedescription>Jump</span><br>
372
373 <ul>
374 <li>$4C - JMP $aaaa </li>
375 <li>$6C - JMP ($aaaa) </li>
376 </ul>
377
378
379
380 <p id=opcodename>JSR</p>
381 <span id=opcodedescription>Jump to subroutine</span><br>
382
383
384 <ul>
385 <li>$20 - JSR $aaaa </li>
386 </ul>
387
388
389
390 <p id=opcodename>LDA</p>
391 <span id=opcodedescription>Load Accumulator with memory</span><br>
392 <span id=opcodeaction>M -> A</span><br>
393 <span id=opcodeflags> N, Z</span><br>
394
395 <ul>
396 <li>$A9 - LDA #aa </li>
397 <li>$A5 - LDA $aa </li>
398 <li>$B5 - LDA $aa,X </li>
399 <li>$AD - LDA $aaaa </li>
400 <li>$BD - LDA $aaaa,X </li>
401 <li>$B9 - LDA $aaaa,Y </li>
402 <li>$A1 - LDA ($aa,X) </li>
403 <li>$B1 - LDA ($aa),Y </li>
404 </ul>
405
406
407
408 <p id=opcodename>LDX</p>
409 <span id=opcodedescription>Load X with Memory</span><br>
410 <span id=opcodeaction>M -> X</span><br>
411 <span id=opcodeflags> N, Z</span><br>
412
413 <ul>
414 <li>$A2 - LDX #aa </li>
415 <li>$A6 - LDX $aa </li>
416 <li>$B6 - LDX $aa,Y </li>
417 <li>$AE - LDX $aaaa </li>
418 <li>$BE - LDX $aaaa,Y </li>
419 </ul>
420
421
422
423 <p id=opcodename>LDY</p>
424 <span id=opcodedescription>Load Y with Memory</span><br>
425 <span id=opcodeaction>M -> Y</span><br>
426 <span id=opcodeflags> N, Z</span><br>
427
428 <ul>
429 <li>$A0 - LDY #aa </li>
430 <li>$A4 - LDY $aa </li>
431 <li>$B4 - LDY $aa,X </li>
432 <li>$AC - LDY $aaaa </li>
433 <li>$BC - LDY $aaaa,X </li>
434 </ul>
435
436
437
438 <p id=opcodename>LSR</p>
439 <span id=opcodedescription>Logical Shift Right</span><br>
440
441 <pre>
442 +-+-+-+-+-+-+-+-+
443 0 -> |7|6|5|4|3|2|1|0| -> C
444 +-+-+-+-+-+-+-+-+</pre>
445
446
447 <span id=opcodeflags>N, Z, C</span><br>
448
449 <ul>
450 <li>$4A - LSR A </li>
451 <li>$46 - LSR $aa </li>
452 <li>$56 - LSR $aa,X </li>
453 <li>$4E - LSR $aaaa </li>
454 <li>$5E - LSR $aaaa,X </li>
455 </ul>
456
457
458
459 <p id=opcodename>NOP</p>
460 <span id=opcodedescription>No Operation</span><br>
461
462 <ul>
463 <li>$EA - NOP </li>
464 </ul>
465
466
467
468 <p id=opcodename>ORA</p>
469 <span id=opcodedescription>OR Memory with Accumulator</span><br>
470 <span id=opcodeaction>A or M -> A</span><br>
471 <span id=opcodeflags> N, Z</span><br>
472
473 <ul>
474 <li>$09 - ORA #aa </li>
475 <li>$05 - ORA $aa </li>
476 <li>$15 - ORA $aa,X </li>
477 <li>$0D - ORA $aaaa </li>
478 <li>$1D - ORA $aaaa,X </li>
479 <li>$19 - ORA $aaaa,Y </li>
480 <li>$01 - ORA ($aa,X) </li>
481 <li>$11 - ORA ($aa),Y </li>
482 </ul>
483
484
485
486 <p id=opcodename>PHA</p>
487 <span id=opcodedescription>Push Accumulator on Stack</span><br>
488 <span id=opcodeaction>A -> Stack</span><br>
489
490 <ul>
491 <li>$48 - PHA </li>
492 </ul>
493
494
495
496 <p id=opcodename>PHP</p>
497 <span id=opcodedescription>Push Processor Status on Stack</span><br>
498 <span id=opcodeaction>P -> Stack</span><br>
499
500 <ul>
501 <li>$08 - PHP </li>
502 </ul>
503
504
505
506 <p id=opcodename>PLA</p>
507 <span id=opcodedescription>Pull Accumulator from Stack</span><br>
508 <span id=opcodeaction>Stack -> A</span><br>
509 <span id=opcodeflags> N, Z</span><br>
510
511 <ul>
512 <li>$68 - PLA </li>
513 </ul>
514
515
516
517 <p id=opcodename>PLP</p>
518 <span id=opcodedescription>Pull Processor Status from Stack</span><br>
519 <span id=opcodeaction>Stack -> P</span><br>
520 <span id=opcodeflags> P from stack</span><br>
521
522 <ul>
523 <li>$28 - PLP </li>
524 </ul>
525
526
527
528 <p id=opcodename>ROL</p>
529 <span id=opcodedescription>Rotate Left</span><br>
530
531 <pre>
532 +-+-+-+-+-+-+-+-+
533 C <- |7|6|5|4|3|2|1|0| <- C
534 +-+-+-+-+-+-+-+-+</pre>
535
536 <span id=opcodeflags>N, Z, C</span><br>
537
538 <ul>
539 <li>$2A - ROL A </li>
540 <li>$26 - ROL $aa </li>
541 <li>$36 - ROL $aa,X </li>
542 <li>$2E - ROL $aaaa </li>
543 <li>$3E - ROL $aaaa,X </li>
544 </ul>
545
546
547
548 <p id=opcodename>ROR</p>
549 <span id=opcodedescription>Rotate Right</span><br>
550 <pre>
551 +-+-+-+-+-+-+-+-+
552 C -> |7|6|5|4|3|2|1|0| -> C
553 +-+-+-+-+-+-+-+-+</pre>
554
555 <span id=opcodeflags>N, Z, C</span><br>
556
557 <ul>
558 <li>$6A - ROR A </li>
559 <li>$66 - ROR $aa </li>
560 <li>$76 - ROR $aa,X </li>
561 <li>$6E - ROR $aaaa </li>
562 <li>$7E - ROR $aaaa,X </li>
563 </ul>
564
565
566
567 <p id=opcodename>RTI</p>
568 <span id=opcodedescription>Return from Interrupt</span><br>
569
570 <ul>
571 <li>$40 - RTI </li>
572 </ul>
573
574
575
576 <p id=opcodename>RTS</p>
577 <span id=opcodedescription>Return from Subroutine</span><br>
578
579 <ul>
580 <li>$60 - RTS </li>
581 </ul>
582
583
584
585 <p id=opcodename>SBC</p>
586 <span id=opcodedescription>Subtract from Accumulator with Carry</span><br>
587 <span id=opcodeaction>A - M - ~C -> A (~C is NOT C)</span><br>
588 <span id=opcodeflags> N, Z, C, V</span><br>
589
590 <ul>
591 <li>$E9 - SBC #aa </li>
592 <li>$E5 - SBC $aa </li>
593 <li>$F5 - SBC $aa,X </li>
594 <li>$ED - SBC $aaaa </li>
595 <li>$FD - SBC $aaaa,X </li>
596 <li>$F9 - SBC $aaaa,Y </li>
597 <li>$E1 - SBC ($aa,X) </li>
598 <li>$F1 - SBC ($aa),Y </li>
599 </ul>
600
601
602
603 <p id=opcodename>SEC</p>
604 <span id=opcodedescription>Set Carry Flag</span><br>
605
606 <ul>
607 <li>$38 - SEC </li>
608 </ul>
609
610
611
612 <p id=opcodename>SED</p>
613 <span id=opcodedescription>Set Decimal Mode</span><br>
614
615 <ul>
616 <li>$F8 - SED </li>
617 </ul>
618
619
620
621 <p id=opcodename>SEI</p>
622 <span id=opcodedescription>Set Interrupt Disable</span><br>
623
624 <ul>
625 <li>$78 - SEI </li>
626 </ul>
627
628
629
630 <p id=opcodename>STA</p>
631 <span id=opcodedescription>Store Accumulator in Memory</span><br>
632
633 <ul>
634 <li>$85 - STA $aa </li>
635 <li>$95 - STA $aa,X </li>
636 <li>$8D - STA $aaaa </li>
637 <li>$9D - STA $aaaa,X </li>
638 <li>$99 - STA $aaaa,Y </li>
639 <li>$81 - STA ($aa,X) </li>
640 <li>$91 - STA ($aa),Y </li>
641 </ul>
642
643
644
645 <p id=opcodename>STX</p>
646 <span id=opcodedescription>Store X in Memory</span><br>
647
648
649 <ul>
650 <li>$86 - STX $aa </li>
651 <li>$96 - STX $aa,Y </li>
652 <li>$8E - STX $aaaa </li>
653 </ul>
654
655
656
657 <p id=opcodename>STY</p>
658 <span id=opcodedescription>Store Y in Memory</span><br>
659
660
661 <ul>
662 <li>$84 - STY $aa </li>
663 <li>$94 - STY $aa,X </li>
664 <li>$8C - STY $aaaa </li>
665 </ul>
666
667
668
669 <p id=opcodename>TAX</p>
670 <span id=opcodedescription>Transfer Accumulator to X</span><br>
671 <span id=opcodeaction>A -> X</span><br>
672 <span id=opcodeflags> N, Z</span><br>
673
674 <ul>
675 <li>$AA - TAX </li>
676 </ul>
677
678
679
680 <p id=opcodename>TAY</p>
681 <span id=opcodedescription>Transfer Accumulator to Y</span><br>
682 <span id=opcodeaction>A -> Y</span><br>
683 <span id=opcodeflags> N, Z</span><br>
684
685 <ul>
686 <li>$A8 - TAY </li>
687 </ul>
688
689
690
691 <p id=opcodename>TSX</p>
692 <span id=opcodedescription>Transfer Stack to X</span><br>
693 <span id=opcodeaction>S -> X</span><br>
694 <span id=opcodeflags> N, Z</span><br>
695
696 <ul>
697 <li>$BA - TSX </li>
698 </ul>
699
700
701
702 <p id=opcodename>TXA</p>
703 <span id=opcodedescription>Transfer X to Accumulator</span><br>
704 <span id=opcodeaction>X -> A</span><br>
705 <span id=opcodeflags> N, Z</span><br>
706
707 <ul>
708 <li>$8A - TXA </li>
709 </ul>
710
711
712
713 <p id=opcodename>TXS</p>
714 <span id=opcodedescription>Transfer X to Stack</span><br>
715 <span id=opcodeaction>X -> S</span><br>
716 <span id=opcodeflags> N, Z</span><br>
717
718 <ul>
719 <li>$9A - TXS </li>
720 </ul>
721
722
723
724 <p id=opcodename>TYA</p>
725 <span id=opcodedescription>Transfer Y to Accumulator</span><br>
726 <span id=opcodeaction>Y -> A</span><br>
727 <span id=opcodeflags> N, Z</span><br>
728
729 <ul>
730 <li>$98 - TYA </li>
731 </ul>
732
733
734
735 <hr>
736 <A href="documentation.htm"><img src="arrow_back.gif"></A>
737 <img src="pics/osdk_logo_small.png">
738 <hr>
739
740 </BODY>
741 </HTML>
742
743

  ViewVC Help
Powered by ViewVC 1.1.26