6502_opcodes.html 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
  2. "http://www.w3.org/TR/html4/strict.dtd">
  3. <html>
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">
  6. <meta http-equiv="Content-Style-Type" content="text/css">
  7. <title>The 6502 Instruction Set Decoded</title>
  8. <style type="text/css"><!--
  9. body { color: black; background: white; font-size: 12pt }
  10. p, h1, h2, h3, td, li { font-family: sans-serif }
  11. a:link { color: #0000EE }
  12. a:visited { color: #551A8B }
  13. table { text-align: center }
  14. .small { font-size: smaller }
  15. .p02 { background: lime }
  16. .pc02 { background: yellow }
  17. .p816 { background: red }
  18. --></style>
  19. </head>
  20. <body>
  21. <p><a href="http://www.llx.com/">LLX</a> &gt;
  22. <a href="/~nparker/">Neil Parker</a> &gt;
  23. <a href="index.html">Apple II</a> &gt; 6502 Instruction Set</p>
  24. <h1>The 6502/65C02/65C816 Instruction Set Decoded</h1>
  25. <h2>Introduction</h2>
  26. <p>
  27. Though the 6502 instruction set has a number of quirks and
  28. irregularities, large portions of it can be broken up into regular
  29. patterns. An understanding of these patterns can be beneficial to
  30. authors of assemblers or disassemblers for 6502 code--for example, the
  31. Apple II ROM uses the information described below to greatly reduce the
  32. size of the instruction tables used by the built-in machine language
  33. disassembler.
  34. </p>
  35. <p>
  36. Note that the discussion below assumes a knowledge of 6502
  37. programming. If you're looking for a tutorial or general programming
  38. reference for the 6502, I recommend starting at <a
  39. href="http://www.6502.org">6502.org</a>. There are also some useful
  40. documents at <a href="http://www.westerndesigncenter.com">Western
  41. Design Center</a>.
  42. </p>
  43. <ul>
  44. <li><a href="#chart">Instruction Chart</a></li>
  45. <li><a href="#ins02">6502 Instructions</a></li>
  46. <li><a href="#insc02">65C02 Instructions</a></li>
  47. <li><a href="#ins816">65C816 Instructions</a></li>
  48. </ul>
  49. <h2><a name="chart">Instruction Chart</a></h2>
  50. <p>
  51. Shown below are the instructions of the 6502, 65C02, and 65C816 processors.
  52. <span class="p02">GREEN UPPERCASE</span> indicates instructions found on
  53. all processors; <span class="pc02">Yellow Mixed Case</span> indicates
  54. instructions introduced on the 65C02, and <span class="p816">red
  55. lowercase</span> indicates instructions found only on the 65C816. The bit
  56. manipulation instructions found only on the Rockwell and WDC versions of
  57. the 65C02 are not included in the table, nor are the "undocumented"
  58. instructions of the original 6502. (However, after noting the search
  59. engine strings commonly used to locate this page, I have added discussions
  60. of these points below.)
  61. </p>
  62. <table border=1 class="small">
  63. <tr>
  64. <td>&nbsp;</td>
  65. <td>x0</td>
  66. <td>x1</td>
  67. <td>x2</td>
  68. <td>x3</td>
  69. <td>x4</td>
  70. <td>x5</td>
  71. <td>x6</td>
  72. <td>x7</td>
  73. <td>x8</td>
  74. <td>x9</td>
  75. <td>xA</td>
  76. <td>xB</td>
  77. <td>xC</td>
  78. <td>xD</td>
  79. <td>xE</td>
  80. <td>xF</td>
  81. </tr>
  82. <tr>
  83. <td>0x</td>
  84. <td class="p02">BRK b</td>
  85. <td class="p02">ORA (d,X)</td>
  86. <td class="p816">cop b</td>
  87. <td class="p816">ora d,S</td>
  88. <td class="pc02">Tsb d</td>
  89. <td class="p02">ORA d</td>
  90. <td class="p02">ASL d</td>
  91. <td class="p816">ora [d]</td>
  92. <td class="p02">PHP</td>
  93. <td class="p02">ORA #</td>
  94. <td class="p02">ASL A</td>
  95. <td class="p816">phd</td>
  96. <td class="pc02">Tsb a</td>
  97. <td class="p02">ORA a</td>
  98. <td class="p02">ASL a</td>
  99. <td class="p816">ora al</td>
  100. </tr>
  101. <tr>
  102. <td>1x</td>
  103. <td class="p02">BPL r</td>
  104. <td class="p02">ORA (d),Y</td>
  105. <td class="pc02">Ora (d)</td>
  106. <td class="p816">ora (d,S),Y</td>
  107. <td class="pc02">Trb d</td>
  108. <td class="p02">ORA d,X</td>
  109. <td class="p02">ASL d,X</td>
  110. <td class="p816">ora [d],Y</td>
  111. <td class="p02">CLC</td>
  112. <td class="p02">ORA a,Y</td>
  113. <td class="pc02">Inc A</td>
  114. <td class="p816">tcs</td>
  115. <td class="pc02">Trb a</td>
  116. <td class="p02">ORA a,X</td>
  117. <td class="p02">ASL a,X</td>
  118. <td class="p816">ora al,X</td>
  119. </tr>
  120. <tr>
  121. <td>2x</td>
  122. <td class="p02">JSR a</td>
  123. <td class="p02">AND (d,X)</td>
  124. <td class="p816">jsl al</td>
  125. <td class="p816">and d,S</td>
  126. <td class="p02">BIT d</td>
  127. <td class="p02">AND d</td>
  128. <td class="p02">ROL d</td>
  129. <td class="p816">and [d]</td>
  130. <td class="p02">PLP</td>
  131. <td class="p02">AND #</td>
  132. <td class="p02">ROL A</td>
  133. <td class="p816">pld</td>
  134. <td class="p02">BIT a</td>
  135. <td class="p02">AND a</td>
  136. <td class="p02">ROL a</td>
  137. <td class="p816">and al</td>
  138. </tr>
  139. <tr>
  140. <td>3x</td>
  141. <td class="p02">BMI r</td>
  142. <td class="p02">AND (d),Y</td>
  143. <td class="pc02">And (d)</td>
  144. <td class="p816">and (d,S),Y</td>
  145. <td class="pc02">Bit d,X</td>
  146. <td class="p02">AND d,X</td>
  147. <td class="p02">ROL d,X</td>
  148. <td class="p816">and [d],Y</td>
  149. <td class="p02">SEC</td>
  150. <td class="p02">AND a,Y</td>
  151. <td class="pc02">Dec A</td>
  152. <td class="p816">tsc</td>
  153. <td class="pc02">Bit a,X</td>
  154. <td class="p02">AND a,X</td>
  155. <td class="p02">ROL a,X</td>
  156. <td class="p816">and al,X</td>
  157. </tr>
  158. <tr>
  159. <td>4x</td>
  160. <td class="p02">RTI</td>
  161. <td class="p02">EOR (d,X)</td>
  162. <td class="p816">wdm</td>
  163. <td class="p816">eor d,S</td>
  164. <td class="p816">mvp s,d</td>
  165. <td class="p02">EOR d</td>
  166. <td class="p02">LSR d</td>
  167. <td class="p816">eor [d]</td>
  168. <td class="p02">PHA</td>
  169. <td class="p02">EOR #</td>
  170. <td class="p02">LSR A</td>
  171. <td class="p816">phk</td>
  172. <td class="p02">JMP a</td>
  173. <td class="p02">EOR a</td>
  174. <td class="p02">LSR a</td>
  175. <td class="p816">eor al</td>
  176. </tr>
  177. <tr>
  178. <td>5x</td>
  179. <td class="p02">BVC r</td>
  180. <td class="p02">EOR (d),Y</td>
  181. <td class="pc02">Eor (d)</td>
  182. <td class="p816">eor (d,S),Y</td>
  183. <td class="p816">mvn s,d</td>
  184. <td class="p02">EOR d,X</td>
  185. <td class="p02">LSR d,X</td>
  186. <td class="p816">eor [d],Y</td>
  187. <td class="p02">CLI</td>
  188. <td class="p02">EOR a,Y</td>
  189. <td class="pc02">Phy</td>
  190. <td class="p816">tcd</td>
  191. <td class="p816">jmp al</td>
  192. <td class="p02">EOR a,X</td>
  193. <td class="p02">LSR a,X</td>
  194. <td class="p816">eor al,X</td>
  195. </tr>
  196. <tr>
  197. <td>6x</td>
  198. <td class="p02">RTS</td>
  199. <td class="p02">ADC (d,X)</td>
  200. <td class="p816">per rl</td>
  201. <td class="p816">adc d,S</td>
  202. <td class="pc02">Stz d</td>
  203. <td class="p02">ADC d</td>
  204. <td class="p02">ROR d</td>
  205. <td class="p816">adc [d]</td>
  206. <td class="p02">PLA</td>
  207. <td class="p02">ADC #</td>
  208. <td class="p02">ROR A</td>
  209. <td class="p816">rtl</td>
  210. <td class="p02">JMP (a)</td>
  211. <td class="p02">ADC a</td>
  212. <td class="p02">ROR a</td>
  213. <td class="p816">adc al</td>
  214. </tr>
  215. <tr>
  216. <td>7x</td>
  217. <td class="p02">BVS r</td>
  218. <td class="p02">ADC (d),Y</td>
  219. <td class="pc02">Adc (d)</td>
  220. <td class="p816">adc (d,S),Y</td>
  221. <td class="pc02">Stz d,X</td>
  222. <td class="p02">ADC d,X</td>
  223. <td class="p02">ROR d,X</td>
  224. <td class="p816">adc [d],Y</td>
  225. <td class="p02">SEI</td>
  226. <td class="p02">ADC a,Y</td>
  227. <td class="pc02">Ply</td>
  228. <td class="p816">tdc</td>
  229. <td class="pc02">Jmp (a,X)</td>
  230. <td class="p02">ADC a,X</td>
  231. <td class="p02">ROR a,X</td>
  232. <td class="p816">adc al,X</td>
  233. </tr>
  234. <tr>
  235. <td>8x</td>
  236. <td class="pc02">Bra r</td>
  237. <td class="p02">STA (d,X)</td>
  238. <td class="p816">brl rl</td>
  239. <td class="p816">sta d,S</td>
  240. <td class="p02">STY d</td>
  241. <td class="p02">STA d</td>
  242. <td class="p02">STX d</td>
  243. <td class="p816">sta [d]</td>
  244. <td class="p02">DEY</td>
  245. <td class="pc02">Bit #</td>
  246. <td class="p02">TXA</td>
  247. <td class="p816">phb</td>
  248. <td class="p02">STY a</td>
  249. <td class="p02">STA a</td>
  250. <td class="p02">STX a</td>
  251. <td class="p816">sta al</td>
  252. </tr>
  253. <tr>
  254. <td>9x</td>
  255. <td class="p02">BCC r</td>
  256. <td class="p02">STA (d),Y</td>
  257. <td class="pc02">Sta (d)</td>
  258. <td class="p816">sta (d,S),Y</td>
  259. <td class="p02">STY d,X</td>
  260. <td class="p02">STA d,X</td>
  261. <td class="p02">STX d,Y</td>
  262. <td class="p816">sta [d],Y</td>
  263. <td class="p02">TYA</td>
  264. <td class="p02">STA a,Y</td>
  265. <td class="p02">TXS</td>
  266. <td class="p816">txy</td>
  267. <td class="pc02">Stz a</td>
  268. <td class="p02">STA a,X</td>
  269. <td class="pc02">Stz a,X</td>
  270. <td class="p816">sta al,X</td>
  271. </tr>
  272. <tr>
  273. <td>Ax</td>
  274. <td class="p02">LDY #</td>
  275. <td class="p02">LDA (d,X)</td>
  276. <td class="p02">LDX #</td>
  277. <td class="p816">lda d,S</td>
  278. <td class="p02">LDY d</td>
  279. <td class="p02">LDA d</td>
  280. <td class="p02">LDX d</td>
  281. <td class="p816">lda [d]</td>
  282. <td class="p02">TAY</td>
  283. <td class="p02">LDA #</td>
  284. <td class="p02">TAX</td>
  285. <td class="p816">plb</td>
  286. <td class="p02">LDY a</td>
  287. <td class="p02">LDA a</td>
  288. <td class="p02">LDX a</td>
  289. <td class="p816">lda al</td>
  290. </tr>
  291. <tr>
  292. <td>Bx</td>
  293. <td class="p02">BCS r</td>
  294. <td class="p02">LDA (d),Y</td>
  295. <td class="pc02">Lda (d)</td>
  296. <td class="p816">lda (d,S),Y</td>
  297. <td class="p02">LDY d,X</td>
  298. <td class="p02">LDA d,X</td>
  299. <td class="p02">LDX d,Y</td>
  300. <td class="p816">lda [d],Y</td>
  301. <td class="p02">CLV</td>
  302. <td class="p02">LDA a,Y</td>
  303. <td class="p02">TSX</td>
  304. <td class="p816">tyx</td>
  305. <td class="p02">LDY a,X</td>
  306. <td class="p02">LDA a,X</td>
  307. <td class="p02">LDX a,Y</td>
  308. <td class="p816">lda al,X</td>
  309. </tr>
  310. <tr>
  311. <td>Cx</td>
  312. <td class="p02">CPY #</td>
  313. <td class="p02">CMP (d,X)</td>
  314. <td class="p816">rep #</td>
  315. <td class="p816">cmp d,S</td>
  316. <td class="p02">CPY d</td>
  317. <td class="p02">CMP d</td>
  318. <td class="p02">DEC d</td>
  319. <td class="p816">cmp [d]</td>
  320. <td class="p02">INY</td>
  321. <td class="p02">CMP #</td>
  322. <td class="p02">DEX</td>
  323. <td class="p816">wai</td>
  324. <td class="p02">CPY a</td>
  325. <td class="p02">CMP a</td>
  326. <td class="p02">DEC a</td>
  327. <td class="p816">cmp al</td>
  328. </tr>
  329. <tr>
  330. <td>Dx</td>
  331. <td class="p02">BNE r</td>
  332. <td class="p02">CMP (d),Y</td>
  333. <td class="pc02">Cmp (d)</td>
  334. <td class="p816">cmp (d,S),Y</td>
  335. <td class="p816">pei d</td>
  336. <td class="p02">CMP d,X</td>
  337. <td class="p02">DEC d,X</td>
  338. <td class="p816">cmp [d],Y</td>
  339. <td class="p02">CLD</td>
  340. <td class="p02">CMP a,Y</td>
  341. <td class="pc02">Phx</td>
  342. <td class="p816">stp</td>
  343. <td class="p816">jml (a)</td>
  344. <td class="p02">CMP a,X</td>
  345. <td class="p02">DEC a,X</td>
  346. <td class="p816">cmp al,X</td>
  347. </tr>
  348. <tr>
  349. <td>Ex</td>
  350. <td class="p02">CPX #</td>
  351. <td class="p02">SBC (d,X)</td>
  352. <td class="p816">sep #</td>
  353. <td class="p816">sbc d,S</td>
  354. <td class="p02">CPX d</td>
  355. <td class="p02">SBC d</td>
  356. <td class="p02">INC d</td>
  357. <td class="p816">sbc [d]</td>
  358. <td class="p02">INX</td>
  359. <td class="p02">SBC #</td>
  360. <td class="p02">NOP</td>
  361. <td class="p816">xba</td>
  362. <td class="p02">CPX a</td>
  363. <td class="p02">SBC a</td>
  364. <td class="p02">INC a</td>
  365. <td class="p816">sbc al</td>
  366. </tr>
  367. <tr>
  368. <td>Fx</td>
  369. <td class="p02">BEQ r</td>
  370. <td class="p02">SBC (d),Y</td>
  371. <td class="pc02">Sbc (d)</td>
  372. <td class="p816">sbc (d,S),Y</td>
  373. <td class="p816">pea a</td>
  374. <td class="p02">SBC d,X</td>
  375. <td class="p02">INC d,X</td>
  376. <td class="p816">sbc [d],Y</td>
  377. <td class="p02">SED</td>
  378. <td class="p02">SBC a,Y</td>
  379. <td class="pc02">Plx</td>
  380. <td class="p816">xce</td>
  381. <td class="p816">jsr (a,X)</td>
  382. <td class="p02">SBC a,X</td>
  383. <td class="p02">INC a,X</td>
  384. <td class="p816">sbc al,X</td>
  385. </tr>
  386. </table>
  387. <h2><a name="ins02">6502 Instructions</a></h2>
  388. <p>
  389. Most instructions that explicitly reference memory locations have bit
  390. patterns of the form <b>aaabbbcc</b>. The <b>aaa</b> and <b>cc</b> bits
  391. determine the opcode, and the <b>bbb</b> bits determine the addressing mode.
  392. </p>
  393. <p>
  394. Instructions with <b>cc</b> = <b>01</b> are the most regular, and are
  395. therefore considered first. The <b>aaa</b> bits determine the opcode
  396. as follows:
  397. </p>
  398. <table border=1>
  399. <tr><td><b>aaa</b></td><td>opcode</td></tr>
  400. <tr><td>000</td><td>ORA</td></tr>
  401. <tr><td>001</td><td>AND</td></tr>
  402. <tr><td>010</td><td>EOR</td></tr>
  403. <tr><td>011</td><td>ADC</td></tr>
  404. <tr><td>100</td><td>STA</td></tr>
  405. <tr><td>101</td><td>LDA</td></tr>
  406. <tr><td>110</td><td>CMP</td></tr>
  407. <tr><td>111</td><td>SBC</td></tr>
  408. </table>
  409. <p>
  410. And the addressing mode (<b>bbb</b>) bits:
  411. </p>
  412. <table border=1>
  413. <tr><td><b>bbb</b></td><td>addressing mode</td></tr>
  414. <tr><td>000</td><td>(zero page,X)</td></tr>
  415. <tr><td>001</td><td>zero page</td></tr>
  416. <tr><td>010</td><td>#immediate</td></tr>
  417. <tr><td>011</td><td>absolute</td></tr>
  418. <tr><td>100</td><td>(zero page),Y</td></tr>
  419. <tr><td>101</td><td>zero page,X</td></tr>
  420. <tr><td>110</td><td>absolute,Y</td></tr>
  421. <tr><td>111</td><td>absolute,X</td></tr>
  422. </table>
  423. <p>
  424. Putting it all together:
  425. </p>
  426. <table border=1>
  427. <tr>
  428. <td>&nbsp;</td>
  429. <td>ORA</td>
  430. <td>AND</td>
  431. <td>EOR</td>
  432. <td>ADC</td>
  433. <td>STA</td>
  434. <td>LDA</td>
  435. <td>CMP</td>
  436. <td>SBC</td>
  437. </tr>
  438. <tr>
  439. <td>(zp,X)</td>
  440. <td>01</td>
  441. <td>21</td>
  442. <td>41</td>
  443. <td>61</td>
  444. <td>81</td>
  445. <td>A1</td>
  446. <td>C1</td>
  447. <td>E1</td>
  448. </tr>
  449. <tr>
  450. <td>zp</td>
  451. <td>05</td>
  452. <td>25</td>
  453. <td>45</td>
  454. <td>65</td>
  455. <td>85</td>
  456. <td>A5</td>
  457. <td>C5</td>
  458. <td>E5</td>
  459. </tr>
  460. <tr>
  461. <td>#</td>
  462. <td>09</td>
  463. <td>29</td>
  464. <td>49</td>
  465. <td>69</td>
  466. <td>&nbsp;</td>
  467. <td>A9</td>
  468. <td>C9</td>
  469. <td>E9</td>
  470. </tr>
  471. <tr>
  472. <td>abs</td>
  473. <td>0D</td>
  474. <td>2D</td>
  475. <td>4D</td>
  476. <td>6D</td>
  477. <td>8D</td>
  478. <td>AD</td>
  479. <td>CD</td>
  480. <td>ED</td>
  481. </tr>
  482. <tr>
  483. <td>(zp),Y</td>
  484. <td>11</td>
  485. <td>31</td>
  486. <td>51</td>
  487. <td>71</td>
  488. <td>91</td>
  489. <td>B1</td>
  490. <td>D1</td>
  491. <td>F1</td>
  492. </tr>
  493. <tr>
  494. <td>zp,X</td>
  495. <td>15</td>
  496. <td>35</td>
  497. <td>55</td>
  498. <td>75</td>
  499. <td>95</td>
  500. <td>B5</td>
  501. <td>D5</td>
  502. <td>F5</td>
  503. </tr>
  504. <tr>
  505. <td>abs,Y</td>
  506. <td>19</td>
  507. <td>39</td>
  508. <td>59</td>
  509. <td>79</td>
  510. <td>99</td>
  511. <td>B9</td>
  512. <td>D9</td>
  513. <td>F9</td>
  514. </tr>
  515. <tr>
  516. <td>abs,X</td>
  517. <td>1D</td>
  518. <td>3D</td>
  519. <td>5D</td>
  520. <td>7D</td>
  521. <td>9D</td>
  522. <td>BD</td>
  523. <td>DD</td>
  524. <td>FD</td>
  525. </tr>
  526. </table>
  527. <p>
  528. The only irregularity is the absence of the nonsensical immediate STA
  529. instruction.
  530. </p>
  531. <p>
  532. Next we consider the <b>cc</b> = <b>10</b> instructions. These have a
  533. completely different set of opcodes:
  534. </p>
  535. <table border=1>
  536. <tr><td><b>aaa</b></td><td>opcode</td></tr>
  537. <tr><td>000</td><td>ASL</td></tr>
  538. <tr><td>001</td><td>ROL</td></tr>
  539. <tr><td>010</td><td>LSR</td></tr>
  540. <tr><td>011</td><td>ROR</td></tr>
  541. <tr><td>100</td><td>STX</td></tr>
  542. <tr><td>101</td><td>LDX</td></tr>
  543. <tr><td>110</td><td>DEC</td></tr>
  544. <tr><td>111</td><td>INC</td></tr>
  545. </table>
  546. <p>
  547. The addressing modes are similar to the <b>01</b> case, but not quite
  548. the same:
  549. </p>
  550. <table border=1>
  551. <tr><td><b>bbb</b></td><td>addressing mode</td></tr>
  552. <tr><td>000</td><td>#immediate</td></tr>
  553. <tr><td>001</td><td>zero page</td></tr>
  554. <tr><td>010</td><td>accumulator</td></tr>
  555. <tr><td>011</td><td>absolute</td></tr>
  556. <tr><td>101</td><td>zero page,X</td></tr>
  557. <tr><td>111</td><td>absolute,X</td></tr>
  558. </table>
  559. <p>
  560. Note that <b>bbb</b> = <b>100</b> and <b>110</b> are missing. Also,
  561. with STX and LDX, "zero page,X" addressing becomes "zero page,Y", and
  562. with LDX, "absolute,X" becomes "absolute,Y".
  563. </p>
  564. <p>
  565. These fit together like this:
  566. </p>
  567. <table border=1>
  568. <tr>
  569. <td>&nbsp;</td>
  570. <td>ASL</td>
  571. <td>ROL</td>
  572. <td>LSR</td>
  573. <td>ROR</td>
  574. <td>STX</td>
  575. <td>LDX</td>
  576. <td>DEC</td>
  577. <td>INC</td>
  578. </tr>
  579. <tr>
  580. <td>#</td>
  581. <td>&nbsp;</td>
  582. <td>&nbsp;</td>
  583. <td>&nbsp;</td>
  584. <td>&nbsp;</td>
  585. <td>&nbsp;</td>
  586. <td>A2</td>
  587. <td>&nbsp;</td>
  588. <td>&nbsp;</td>
  589. </tr>
  590. <tr>
  591. <td>zp</td>
  592. <td>06</td>
  593. <td>26</td>
  594. <td>46</td>
  595. <td>66</td>
  596. <td>86</td>
  597. <td>A6</td>
  598. <td>C6</td>
  599. <td>E6</td>
  600. </tr>
  601. <tr>
  602. <td>A</td>
  603. <td>0A</td>
  604. <td>2A</td>
  605. <td>4A</td>
  606. <td>6A</td>
  607. <td>&nbsp;</td>
  608. <td>&nbsp;</td>
  609. <td>&nbsp;</td>
  610. <td>&nbsp;</td>
  611. </tr>
  612. <tr>
  613. <td>abs</td>
  614. <td>0E</td>
  615. <td>2E</td>
  616. <td>4E</td>
  617. <td>6E</td>
  618. <td>8E</td>
  619. <td>AE</td>
  620. <td>CE</td>
  621. <td>EE</td>
  622. </tr>
  623. <tr>
  624. <td>zp,X/zp,Y</td>
  625. <td>16</td>
  626. <td>36</td>
  627. <td>56</td>
  628. <td>76</td>
  629. <td>96</td>
  630. <td>B6</td>
  631. <td>D6</td>
  632. <td>F6</td>
  633. </tr>
  634. <tr>
  635. <td>abs,X/abs,Y</td>
  636. <td>1E</td>
  637. <td>3E</td>
  638. <td>5E</td>
  639. <td>7E</td>
  640. <td>&nbsp;</td>
  641. <td>BE</td>
  642. <td>DE</td>
  643. <td>FE</td>
  644. </tr>
  645. </table>
  646. <p>
  647. Most of the gaps in this table are easy to understand. Immediate mode
  648. makes no sense for any instruction other than LDX, and accumulator mode
  649. for DEC and INC didn't appear until the 65C02. The slots that "STX A"
  650. and "LDX A" would occupy are taken by TXA and TAX respectively, which is
  651. exactly what one would expect. The only inexplicable gap is the
  652. absence of a "STX abs,Y" instruction.
  653. </p>
  654. <p>
  655. Next, the <b>cc</b> = <b>00</b> instructions. Again, the opcodes are
  656. different:
  657. </p>
  658. <table border=1>
  659. <tr><td><b>aaa</b></td><td>opcode</td></tr>
  660. <tr><td>001</td><td>BIT</td></tr>
  661. <tr><td>010</td><td>JMP</td></tr>
  662. <tr><td>011</td><td>JMP (abs)</td></tr>
  663. <tr><td>100</td><td>STY</td></tr>
  664. <tr><td>101</td><td>LDY</td></tr>
  665. <tr><td>110</td><td>CPY</td></tr>
  666. <tr><td>111</td><td>CPX</td></tr>
  667. </table>
  668. <p>
  669. It's debatable whether the JMP instructions belong in this
  670. list...I've included them because they <em>do</em> seem to fit,
  671. provided one considers the indirect JMP a separate opcode rather than
  672. a different addressing mode of the absolute JMP.
  673. </p>
  674. <p>
  675. The addressing modes are the same as the <b>10</b> case, except that
  676. accumulator mode is missing.
  677. </p>
  678. <table border=1>
  679. <tr><td><b>bbb</b></td><td>addressing mode</td></tr>
  680. <tr><td>000</td><td>#immediate</td></tr>
  681. <tr><td>001</td><td>zero page</td></tr>
  682. <tr><td>011</td><td>absolute</td></tr>
  683. <tr><td>101</td><td>zero page,X</td></tr>
  684. <tr><td>111</td><td>absolute,X</td></tr>
  685. </table>
  686. <p>
  687. And here's how they fit together:
  688. </p>
  689. <table border=1>
  690. <tr>
  691. <td>&nbsp;</td>
  692. <td>BIT</td>
  693. <td>JMP</td>
  694. <td>JMP()</td>
  695. <td>STY</td>
  696. <td>LDY</td>
  697. <td>CPY</td>
  698. <td>CPX</td>
  699. </tr>
  700. <tr>
  701. <td>#</td>
  702. <td>&nbsp;</td>
  703. <td>&nbsp;</td>
  704. <td>&nbsp;</td>
  705. <td>&nbsp;</td>
  706. <td>A0</td>
  707. <td>C0</td>
  708. <td>E0</td>
  709. </tr>
  710. <tr>
  711. <td>zp</td>
  712. <td>24</td>
  713. <td>&nbsp;</td>
  714. <td>&nbsp;</td>
  715. <td>84</td>
  716. <td>A4</td>
  717. <td>C4</td>
  718. <td>E4</td>
  719. </tr>
  720. <tr>
  721. <td>abs</td>
  722. <td>2C</td>
  723. <td>4C</td>
  724. <td>6C</td>
  725. <td>8C</td>
  726. <td>AC</td>
  727. <td>CC</td>
  728. <td>EC</td>
  729. </tr>
  730. <tr>
  731. <td>zp,X</td>
  732. <td>&nbsp;</td>
  733. <td>&nbsp;</td>
  734. <td>&nbsp;</td>
  735. <td>94</td>
  736. <td>B4</td>
  737. <td>&nbsp;</td>
  738. <td>&nbsp;</td>
  739. </tr>
  740. <tr>
  741. <td>abs,X</td>
  742. <td>&nbsp;</td>
  743. <td>&nbsp;</td>
  744. <td>&nbsp;</td>
  745. <td>&nbsp;</td>
  746. <td>BC</td>
  747. <td>&nbsp;</td>
  748. <td>&nbsp;</td>
  749. </tr>
  750. </table>
  751. <p>
  752. Some of the gaps in this table are understandable (e.g. the lack of an
  753. immediate mode for JMP, JMP(), and STY), but others are not
  754. (e.g. the absence of "zp,X" for CPY and CPX, and the absence of "abs,X"
  755. for STY, CPY, and CPX). Note that if accumulator mode (<b>bbb</b> =
  756. <b>010</b>) were available, "LDY A" would be A8, which falls in the
  757. slot occupied by TAY, but the pattern breaks down elsewhere--TYA is 98,
  758. rather than 88, which we would expect it to be if it corresponded to
  759. the nonexistant "STY A".
  760. </p>
  761. <p>
  762. No instructions have the form <b>aaabbb11</b>.
  763. </p>
  764. <p>
  765. The conditional branch instructions all have the form <b>xxy10000</b>.
  766. The flag indicated by <b>xx</b> is compared with <b>y</b>, and the
  767. branch is taken if they are equal.
  768. </p>
  769. <table border=1>
  770. <tr><td><b>xx</b></td><td>flag</td></tr>
  771. <tr><td>00</td><td>negative</td></tr>
  772. <tr><td>01</td><td>overflow</td></tr>
  773. <tr><td>10</td><td>carry</td></tr>
  774. <tr><td>11</td><td>zero</td></tr>
  775. </table>
  776. <p>
  777. This gives the following branches:
  778. </p>
  779. <table border=1>
  780. <tr><td>BPL</td><td>BMI</td><td>BVC</td><td>BVS</td><td>BCC</td><td>BCS</td>
  781. <td>BNE</td><td>BEQ</td></tr>
  782. <tr><td>10</td><td>30</td><td>50</td><td>70</td><td>90</td><td>B0</td>
  783. <td>D0</td><td>F0</td>
  784. </table>
  785. <p>
  786. The remaining instructions are probably best considered simply by
  787. listing them. Here are the interrupt and subroutine instructions:
  788. </p>
  789. <table border=1>
  790. <tr><td>BRK</td><td>JSR abs</td><td>RTI</td><td>RTS</td></tr>
  791. <tr><td>00</td><td>20</td><td>40</td><td>60</td>
  792. </table>
  793. <p>
  794. (JSR is the only absolute-addressing instruction that doesn't fit the
  795. <b>aaabbbcc</b> pattern.)
  796. </p>
  797. <p>
  798. Other single-byte instructions:
  799. </p>
  800. <table border=1 style="margin-bottom: 10px">
  801. <tr>
  802. <td>PHP</td>
  803. <td>PLP</td>
  804. <td>PHA</td>
  805. <td>PLA</td>
  806. <td>DEY</td>
  807. <td>TAY</td>
  808. <td>INY</td>
  809. <td>INX</td>
  810. </tr>
  811. <tr>
  812. <td>08</td>
  813. <td>28</td>
  814. <td>48</td>
  815. <td>68</td>
  816. <td>88</td>
  817. <td>A8</td>
  818. <td>C8</td>
  819. <td>E8</td>
  820. </tr>
  821. </table>
  822. <table border=1 style="margin-bottom: 10px">
  823. <tr>
  824. <td>CLC</td>
  825. <td>SEC</td>
  826. <td>CLI</td>
  827. <td>SEI</td>
  828. <td>TYA</td>
  829. <td>CLV</td>
  830. <td>CLD</td>
  831. <td>SED</td>
  832. </tr>
  833. <tr>
  834. <td>18</td>
  835. <td>38</td>
  836. <td>58</td>
  837. <td>78</td>
  838. <td>98</td>
  839. <td>B8</td>
  840. <td>D8</td>
  841. <td>F8</td>
  842. </tr>
  843. </table>
  844. <table border=1>
  845. <tr>
  846. <td>TXA</td>
  847. <td>TXS</td>
  848. <td>TAX</td>
  849. <td>TSX</td>
  850. <td>DEX</td>
  851. <td>NOP</td>
  852. </tr>
  853. <tr>
  854. <td>8A</td>
  855. <td>9A</td>
  856. <td>AA</td>
  857. <td>BA</td>
  858. <td>CA</td>
  859. <td>EA</td>
  860. </tr>
  861. </table>
  862. <h3>"Undocumented" 6502 instructions</h3>
  863. <p>
  864. The above-described instructions (the ones shown in <span
  865. class="p02">GREEN UPPERCASE</span> in the table at the top of this
  866. page) are the only ones documented in any manufacturer's official data
  867. sheets. The question often arises, "What do all those other leftover
  868. bytes do if you try to execute them as instructions?"
  869. <p>
  870. In general the behavior of instructions other than those listed above
  871. cannot be described exactly, as they tend to be somewhat unstable, and
  872. do not always behave the same way on chips made by different
  873. manufacturers, and some instructions don't even behave the same way
  874. twice on the same chip. Those looking for a precise listing of
  875. "undocumented" instruction behaviors will have to look elsewhere, and
  876. should beware that the behaviors described on other web pages may be
  877. specific to 6502s made by a particular (often unspecified) manufacturer.
  878. </p>
  879. <p>
  880. However, there are some facts that seem to be common across all 6502s.
  881. The most insteresting case is the <b>cc</b> = <b>11</b> instructions:
  882. these execute the adjacent <b>cc</b> = <b>01</b> and <b>cc</b> =
  883. <b>10</b> instructions <em>simultaneously</em>. For example, <b>AF</b>
  884. executes <b>AD</b> ("LDA absolute") and <b>AE</b> ("LDX absolute") at
  885. the same time, putting the same value in both the accumulator and the X
  886. register.
  887. </p>
  888. <p>
  889. In some cases the <b>01</b> and <b>10</b> instructions are
  890. incompatible. For example, <b>8F</b> executes <b>8D</b> ("STA
  891. absolute") and <b>8E</b> ("STX absolute") at the same time. So which
  892. register actually gets written to memory? Usually some mixture of the
  893. two, in a manner that varies depending on who made the 6502, when it was
  894. made, the phase of the moon, and other unpredictable variables.
  895. </p>
  896. <p>
  897. The behavior of the <b>11</b> instructions is especially problematic in
  898. those cases where the adjacent <b>01</b> or <b>10</b> instruction is also
  899. undocumented. Sometimes you can get a partial idea of what happens by
  900. looking at what the missing <b>01</b> or <b>10</b> instruction would be
  901. if that opcode/addressing mode combination weren't missing.
  902. <b>Xxxx1011</b> instructions are also problematic--some of these seem
  903. to mix not only the adjacent <b>01</b> and <b>10</b> instructions, but
  904. also the immediate mode of the corresponding <b>10</b> instruction.
  905. </p>
  906. <p>
  907. Most of the missing <b>00</b>, <b>01</b>, and <b>10</b> instructions
  908. seem to behave like NOPs, but using the addressing mode indicated by
  909. the <b>bbb</b> bits. But apparently this isn't always reliable--there
  910. are reports of some of these instructions occasionally locking up the
  911. processor.
  912. </p>
  913. <p>
  914. Instructions of the form <b>xxxx0010</b> usually lock up the processor,
  915. so that a reset is required to recover. The instructions <b>82</b>,
  916. <b>C2</b>, and <b>E2</b> (corresponding to the nonexistant immediate
  917. mode of STX, DEC, and INC) may sometimes behave as two-byte NOPs, but don't
  918. count on it.
  919. </p>
  920. <h2><a name="insc02">65C02 Instructions</a></h2>
  921. <p>
  922. The new instructions of the 65C02 are much less logical than those
  923. listed above. The designers of the 65C02 apparently chose to continue
  924. leaving the <b>cc</b> = <b>11</b> instructions empty, and this didn't
  925. leave much space for new instructions. Some instructions landed in
  926. logical places, but others had to be assigned wherever there was room,
  927. whether it made sense or not.
  928. </p>
  929. <p>
  930. The new zero-page indirect addressing mode fills the previously-unused
  931. <b>bbb</b> = <b>100</b> slot of the <b>cc</b> = <b>10</b> instructions,
  932. but the opcodes are those of the <b>cc</b> = <b>01</b> instructions.
  933. </p>
  934. <table border=1>
  935. <tr>
  936. <td>&nbsp;</td>
  937. <td>ORA</td>
  938. <td>AND</td>
  939. <td>EOR</td>
  940. <td>ADC</td>
  941. <td>STA</td>
  942. <td>LDA</td>
  943. <td>CMP</td>
  944. <td>SBC</td>
  945. </tr>
  946. <tr>
  947. <td>(zp)</td>
  948. <td>12</td>
  949. <td>32</td>
  950. <td>52</td>
  951. <td>72</td>
  952. <td>92</td>
  953. <td>B2</td>
  954. <td>D2</td>
  955. <td>F2</td>
  956. </tr>
  957. </table>
  958. <p>
  959. "JMP (abs,X)" is right where it ought to be (<b>011 111 00</b>), if one
  960. continues to regard the indirect JMP as a separate opcode from the
  961. absolute JMP:
  962. </p>
  963. <table border=1>
  964. <tr>
  965. <td>&nbsp;</td>
  966. <td>JMP()</td>
  967. </tr>
  968. <tr>
  969. <td>abs,X</td>
  970. <td>7C</td>
  971. </tr>
  972. </table>
  973. <p>
  974. "BIT zp,X" and "BIT abs,X" ended up exactly where one would expect them
  975. to be, but "BIT #" had to be moved because its slot was already taken by
  976. JSR:
  977. </p>
  978. <table border=1>
  979. <tr>
  980. <td>&nbsp;</td>
  981. <td>BIT</td>
  982. </tr>
  983. <tr>
  984. <td>#</td>
  985. <td>89</td>
  986. </tr>
  987. <tr>
  988. <td>zp,X</td>
  989. <td>34</td>
  990. </tr>
  991. <tr>
  992. <td>abs,X</td>
  993. <td>3C</td>
  994. </tr>
  995. </table>
  996. <p>
  997. TSB ended up in a reasonable place (<b>000bbb00</b>):
  998. </p>
  999. <table border=1>
  1000. <tr>
  1001. <td>&nbsp;</td>
  1002. <td>TSB</td>
  1003. </tr>
  1004. <tr>
  1005. <td>zp</td>
  1006. <td>04</td>
  1007. </tr>
  1008. <tr>
  1009. <td>abs</td>
  1010. <td>0C</td>
  1011. </tr>
  1012. </table>
  1013. <p>
  1014. But the above assigments exhaust the logical possibilities for
  1015. opcodes that explicity reference memory locations, so TRB and STZ had to
  1016. be put wherever room could be found:
  1017. </p>
  1018. <table border=1>
  1019. <tr>
  1020. <td>&nbsp;</td>
  1021. <td>TRB</td>
  1022. <td>STZ</td>
  1023. </tr>
  1024. <tr>
  1025. <td>zp</td>
  1026. <td>14</td>
  1027. <td>64</td>
  1028. </tr>
  1029. <tr>
  1030. <td>abs</td>
  1031. <td>1C</td>
  1032. <td>9C</td>
  1033. </tr>
  1034. <tr>
  1035. <td>zp,X</td>
  1036. <td>&nbsp;</td>
  1037. <td>74</td>
  1038. </tr>
  1039. <tr>
  1040. <td>abs,X</td>
  1041. <td>&nbsp;</td>
  1042. <td>9E</td>
  1043. </tr>
  1044. </table>
  1045. <p>
  1046. That leaves the relative branch instruction
  1047. </p>
  1048. <table border=1>
  1049. <tr>
  1050. <td>BRA</td>
  1051. </tr>
  1052. <tr>
  1053. <td>80</td>
  1054. </tr>
  1055. </table>
  1056. <p>
  1057. and the single-byte instructions:
  1058. </p>
  1059. <table border=1>
  1060. <tr>
  1061. <td>INC A</td>
  1062. <td>DEC A</td>
  1063. <td>PHY</td>
  1064. <td>PLY</td>
  1065. <td>PHX</td>
  1066. <td>PLX</td>
  1067. </tr>
  1068. <tr>
  1069. <td>1A</td>
  1070. <td>3A</td>
  1071. <td>5A</td>
  1072. <td>7A</td>
  1073. <td>DA</td>
  1074. <td>FA</td>
  1075. </tr>
  1076. </table>
  1077. <h3>Additional instructions found on some 65C02s</h3>
  1078. <p>
  1079. Actually, I lied when I said above that the designers of the 65C02
  1080. chose to leave the <b>cc</b> = <b>11</b> instructions unused. On
  1081. 65C02s made by Rockwell and by WDC, some of these instructions are used
  1082. for additional bit setting, clearing, and testing instructions. These
  1083. instructions are missing on 65C02s made by other manufacturers. (And
  1084. since this page is part of a set of Apple II-related pages, I should
  1085. point out that Apple never shipped any computers that used Rockwell or
  1086. WDC 65C02s, so none of the instructions in this section are available
  1087. on an unmodified Apple II.)
  1088. </p>
  1089. <p>
  1090. The bit set and clear instructions have the form <b>xyyy0111</b>,
  1091. where <b>x</b> is 0 to clear a bit or 1 to set it, and <b>yyy</b> is
  1092. which bit at the memory location to set or clear.
  1093. </p>
  1094. <table border=1 style="margin-bottom: 10px">
  1095. <tr>
  1096. <td>&nbsp;</td>
  1097. <td>RMB0</td>
  1098. <td>RMB1</td>
  1099. <td>RMB2</td>
  1100. <td>RMB3</td>
  1101. <td>RMB4</td>
  1102. <td>RMB5</td>
  1103. <td>RMB6</td>
  1104. <td>RMB7</td>
  1105. </tr>
  1106. <tr>
  1107. <td>zp</td>
  1108. <td>07</td>
  1109. <td>17</td>
  1110. <td>27</td>
  1111. <td>37</td>
  1112. <td>47</td>
  1113. <td>57</td>
  1114. <td>67</td>
  1115. <td>77</td>
  1116. </tr>
  1117. </table>
  1118. <table border=1>
  1119. <tr>
  1120. <td>&nbsp;</td>
  1121. <td>SMB0</td>
  1122. <td>SMB1</td>
  1123. <td>SMB2</td>
  1124. <td>SMB3</td>
  1125. <td>SMB4</td>
  1126. <td>SMB5</td>
  1127. <td>SMB6</td>
  1128. <td>SMB7</td>
  1129. </tr>
  1130. <tr>
  1131. <td>zp</td>
  1132. <td>87</td>
  1133. <td>97</td>
  1134. <td>A7</td>
  1135. <td>B7</td>
  1136. <td>C7</td>
  1137. <td>D7</td>
  1138. <td>E7</td>
  1139. <td>F7</td>
  1140. </tr>
  1141. </table>
  1142. <p>
  1143. Similarly, the test-and-branch instructions are of the form
  1144. <b>xyyy1111</b>, where <b>x</b> is 0 to test whether the bit is 0, or
  1145. 1 to test whether it is 1, and <b>yyy</b> is which bit to test.
  1146. </p>
  1147. <table border=1 style="margin-bottom: 10px">
  1148. <tr>
  1149. <td>&nbsp;</td>
  1150. <td>BBR0</td>
  1151. <td>BBR1</td>
  1152. <td>BBR2</td>
  1153. <td>BBR3</td>
  1154. <td>BBR4</td>
  1155. <td>BBR5</td>
  1156. <td>BBR6</td>
  1157. <td>BBR7</td>
  1158. </tr>
  1159. <tr>
  1160. <td>zp,rel</td>
  1161. <td>0F</td>
  1162. <td>1F</td>
  1163. <td>2F</td>
  1164. <td>3F</td>
  1165. <td>4F</td>
  1166. <td>5F</td>
  1167. <td>6F</td>
  1168. <td>7F</td>
  1169. </tr>
  1170. </table>
  1171. <table border=1>
  1172. <tr>
  1173. <td>&nbsp;</td>
  1174. <td>BBS0</td>
  1175. <td>BBS1</td>
  1176. <td>BBS2</td>
  1177. <td>BBS3</td>
  1178. <td>BBS4</td>
  1179. <td>BBS5</td>
  1180. <td>BBS6</td>
  1181. <td>BBS7</td>
  1182. </tr>
  1183. <tr>
  1184. <td>zp,rel</td>
  1185. <td>8F</td>
  1186. <td>9F</td>
  1187. <td>AF</td>
  1188. <td>BF</td>
  1189. <td>CF</td>
  1190. <td>DF</td>
  1191. <td>EF</td>
  1192. <td>FF</td>
  1193. </tr>
  1194. </table>
  1195. <p>
  1196. Additionally, the WDC version of the 65C02 includes the 65C816's STP and
  1197. WAI instructions (see below).
  1198. </p>
  1199. <h3>"Undocumented" 65C02 Instructions</h3>
  1200. <p>
  1201. There aren't really any undocumented instructions on the 65C02--any
  1202. instructions not listed above are documented as performing no
  1203. operation.
  1204. </p>
  1205. <p>
  1206. However, these alternate NOPs are not created equal. Some have one- or
  1207. two-byte operands (which they don't do anything with), and they take
  1208. different amounts of time to execute.
  1209. </p>
  1210. <table border=1>
  1211. <tr><td>Instruction</td><td>Bytes</td><td>Cycles</td></tr>
  1212. <tr><td>xxxxxx10</td><td>2</td><td>2</td></tr>
  1213. <tr><td>xxxxxx11</td><td>1</td><td>1</td></tr>
  1214. <tr><td>01000100</td><td>2</td><td>3</td></tr>
  1215. <tr><td>x1x10100</td><td>2</td><td>4</td></tr>
  1216. <tr><td>01011100</td><td>3</td><td>8</td></tr>
  1217. <tr><td>11x11100</td><td>3</td><td>4</td></tr>
  1218. </table>
  1219. <p>Actually, it's not quite correct to say that these instructions don't do
  1220. anything with their operands. A memory read <em>does</em> occur,
  1221. generally using the addressing mode you would expect from the bit
  1222. patterns--which may be significant if there happens to be a memory-mapped
  1223. hardware device at the target address.</p>
  1224. <p>A correspondent with appropriate testing hardware reports that the
  1225. behavior of 01011100 (5C) is strange: "5C bb aa", after fetching its
  1226. three bytes, accesses FFbb, and then spends four cycles accessing FFFF.</p>
  1227. <h2><a name="ins816">65C816 Instructions</a></h2>
  1228. <p>
  1229. The 65C816 uses the <b>cc</b> = <b>11</b> instructions, but not for
  1230. Rockwell bit-manipulation opcodes.
  1231. Most of these are put to work supplying the new long addressing modes
  1232. of the 65C816:
  1233. </p>
  1234. <table border=1>
  1235. <tr><td><b>bbb</b></td><td>addressing mode</td></tr>
  1236. <tr><td>000</td><td>offset,S</td></tr>
  1237. <tr><td>001</td><td>[direct page]</td></tr>
  1238. <tr><td>011</td><td>absolute long</td></tr>
  1239. <tr><td>100</td><td>(offset,S),Y</td></tr>
  1240. <tr><td>101</td><td>[direct page],Y</td></tr>
  1241. <tr><td>111</td><td>absolute long,X</td></tr>
  1242. </table>
  1243. <p>
  1244. These combine with the <b>01</b> opcodes:
  1245. </p>
  1246. <table border=1>
  1247. <tr>
  1248. <td>&nbsp;</td>
  1249. <td>ORA</td>
  1250. <td>AND</td>
  1251. <td>EOR</td>
  1252. <td>ADC</td>
  1253. <td>STA</td>
  1254. <td>LDA</td>
  1255. <td>CMP</td>
  1256. <td>SBC</td>
  1257. </tr>
  1258. <tr>
  1259. <td>d,S</td>
  1260. <td>03</td>
  1261. <td>23</td>
  1262. <td>43</td>
  1263. <td>63</td>
  1264. <td>83</td>
  1265. <td>A3</td>
  1266. <td>C3</td>
  1267. <td>E3</td>
  1268. </tr>
  1269. <tr>
  1270. <td>[dp]</td>
  1271. <td>07</td>
  1272. <td>27</td>
  1273. <td>47</td>
  1274. <td>67</td>
  1275. <td>87</td>
  1276. <td>A7</td>
  1277. <td>C7</td>
  1278. <td>E7</td>
  1279. </tr>
  1280. <tr>
  1281. <td>al</td>
  1282. <td>0F</td>
  1283. <td>2F</td>
  1284. <td>4F</td>
  1285. <td>6F</td>
  1286. <td>8F</td>
  1287. <td>AF</td>
  1288. <td>CF</td>
  1289. <td>EF</td>
  1290. </tr>
  1291. <tr>
  1292. <td>(d,S),Y</td>
  1293. <td>13</td>
  1294. <td>33</td>
  1295. <td>53</td>
  1296. <td>73</td>
  1297. <td>93</td>
  1298. <td>B3</td>
  1299. <td>D3</td>
  1300. <td>F3</td>
  1301. </tr>
  1302. <tr>
  1303. <td>[dp],Y</td>
  1304. <td>17</td>
  1305. <td>37</td>
  1306. <td>57</td>
  1307. <td>77</td>
  1308. <td>97</td>
  1309. <td>B7</td>
  1310. <td>D7</td>
  1311. <td>F7</td>
  1312. </tr>
  1313. <tr>
  1314. <td>al,X</td>
  1315. <td>1F</td>
  1316. <td>3F</td>
  1317. <td>5F</td>
  1318. <td>7F</td>
  1319. <td>9F</td>
  1320. <td>BF</td>
  1321. <td>DF</td>
  1322. <td>FF</td>
  1323. </tr>
  1324. </table>
  1325. <p>
  1326. The missing <b>010</b> and <b>110</b> instructions are all single-byte
  1327. instructions:
  1328. </p>
  1329. <table border=1 style="margin-bottom: 10px">
  1330. <tr>
  1331. <td>PHD</td>
  1332. <td>PLD</td>
  1333. <td>PHK</td>
  1334. <td>RTL</td>
  1335. <td>PHB</td>
  1336. <td>PLB</td>
  1337. <td>WAI</td>
  1338. <td>XBA</td>
  1339. </tr>
  1340. <tr>
  1341. <td>0B</td>
  1342. <td>2B</td>
  1343. <td>4B</td>
  1344. <td>6B</td>
  1345. <td>8B</td>
  1346. <td>AB</td>
  1347. <td>CB</td>
  1348. <td>EB</td>
  1349. </tr>
  1350. </table>
  1351. <table border=1>
  1352. <tr>
  1353. <td>TCS</td>
  1354. <td>TSC</td>
  1355. <td>TCD</td>
  1356. <td>TDC</td>
  1357. <td>TXY</td>
  1358. <td>TYX</td>
  1359. <td>STP</td>
  1360. <td>XCE</td>
  1361. </tr>
  1362. <tr>
  1363. <td>1B</td>
  1364. <td>3B</td>
  1365. <td>5B</td>
  1366. <td>7B</td>
  1367. <td>9B</td>
  1368. <td>BB</td>
  1369. <td>DB</td>
  1370. <td>FB</td>
  1371. </tr>
  1372. </table>
  1373. <p>
  1374. The remaining instructions are a grab-bag assigned to the few remaining
  1375. unused positions:
  1376. </p>
  1377. <table border=1>
  1378. <tr><td>COP sig</td><td>02</td></tr>
  1379. <tr><td>JSL al</td><td>22</td></tr>
  1380. <tr><td>WDM</td><td>42</td></tr>
  1381. <tr><td>PER rl</td><td>62</td></tr>
  1382. <tr><td>BRL rl</td><td>82</td></tr>
  1383. <tr><td>REP #</td><td>C2</td></tr>
  1384. <tr><td>SEP #</td><td>E2</td></tr>
  1385. <tr><td>MVP sb,db</td><td>44</td></tr>
  1386. <tr><td>MVN sb,db</td><td>54</td></tr>
  1387. <tr><td>PEI dp</td><td>D4</td></tr>
  1388. <tr><td>PEA abs</td><td>F4</td></tr>
  1389. <tr><td>JMP al</td><td>5C</td></tr>
  1390. <tr><td>JML (abs)</td><td>DC</td></tr>
  1391. <tr><td>JSR (abs,X)</td><td>FC</td></tr>
  1392. </table>
  1393. <p><a href="http://www.llx.com/">LLX</a> &gt;
  1394. <a href="/~nparker/">Neil Parker</a> &gt;
  1395. <a href="index.html">Apple II</a> &gt; 6502 Instruction Set</p>
  1396. <p>
  1397. <small>Original: July 27, 2004<br>
  1398. Modified: May 3, 2005<br>
  1399. Modified: May 29, 2016--Added a new note about 65C02 "undocumented" opcodes</small>
  1400. </p>
  1401. </body>
  1402. </html>