<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://7800.8bitdev.org/index.php?action=history&amp;feed=atom&amp;title=6502_Advanced_Tips</id>
		<title>6502 Advanced Tips - Revision history</title>
		<link rel="self" type="application/atom+xml" href="https://7800.8bitdev.org/index.php?action=history&amp;feed=atom&amp;title=6502_Advanced_Tips"/>
		<link rel="alternate" type="text/html" href="https://7800.8bitdev.org/index.php?title=6502_Advanced_Tips&amp;action=history"/>
		<updated>2026-05-13T13:43:44Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.28.0</generator>

	<entry>
		<id>https://7800.8bitdev.org/index.php?title=6502_Advanced_Tips&amp;diff=567&amp;oldid=prev</id>
		<title>MSaarna at 17:10, 26 September 2018</title>
		<link rel="alternate" type="text/html" href="https://7800.8bitdev.org/index.php?title=6502_Advanced_Tips&amp;diff=567&amp;oldid=prev"/>
				<updated>2018-09-26T17:10:01Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;a href=&quot;https://7800.8bitdev.org/index.php?title=6502_Advanced_Tips&amp;amp;diff=567&amp;amp;oldid=198&quot;&gt;Show changes&lt;/a&gt;</summary>
		<author><name>MSaarna</name></author>	</entry>

	<entry>
		<id>https://7800.8bitdev.org/index.php?title=6502_Advanced_Tips&amp;diff=198&amp;oldid=prev</id>
		<title>MSaarna: Created page with &quot;==jump table instead of comparison branch chains==  When you need to choose between 4 or more destinations, it's more efficient to use a jump table instead of a sequence of CM...&quot;</title>
		<link rel="alternate" type="text/html" href="https://7800.8bitdev.org/index.php?title=6502_Advanced_Tips&amp;diff=198&amp;oldid=prev"/>
				<updated>2015-12-22T18:52:07Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;==jump table instead of comparison branch chains==  When you need to choose between 4 or more destinations, it&amp;#039;s more efficient to use a jump table instead of a sequence of CM...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==jump table instead of comparison branch chains==&lt;br /&gt;
&lt;br /&gt;
When you need to choose between 4 or more destinations, it's more efficient to use a jump table instead of a sequence of CMP and BEQ. Here's a jump table example that uses RTS instead of JMP (ADDRESS) to save even more  ROM and cycles...&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   LDX FunctionIndex&lt;br /&gt;
   LDA FunctionJumptablehi,x&lt;br /&gt;
   PHA&lt;br /&gt;
   LDA FunctionJumptablelo,x&lt;br /&gt;
   PHA&lt;br /&gt;
   RTS&lt;br /&gt;
 FunctionJumptablehi&lt;br /&gt;
   .byte &amp;gt;(ClearRam-1)&lt;br /&gt;
   .byte &amp;gt;(SetRam-1)&lt;br /&gt;
   .byte &amp;gt;(MemCpy-1)&lt;br /&gt;
   .byte &amp;gt;(MemCmp-1)&lt;br /&gt;
 FunctionJumptablelo&lt;br /&gt;
   .byte &amp;lt;(ClearRam-1)&lt;br /&gt;
   .byte &amp;lt;(SetRam-1)&lt;br /&gt;
   .byte &amp;lt;(MemCpy-1)&lt;br /&gt;
   .byte &amp;lt;(MemCmp-1)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==fast range test==&lt;br /&gt;
&lt;br /&gt;
For all of these we assume that the byte to be tested is in A and that the start and end values, n and m, are already defined. Also that 0 &amp;lt; n &amp;lt; m &amp;lt; $FF.&lt;br /&gt;
&lt;br /&gt;
If you don't need to preserve the byte in A then testing the byte can be done in five bytes and only six cycles. This sets the carry if A is in the range n to m.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 CLC		; clear carry for add&lt;br /&gt;
 ADC	#$FF-m	; make m = $FF&lt;br /&gt;
 ADC	#m-n+1	; carry set if in range n to m&lt;br /&gt;
&lt;br /&gt;
Courtesy Lee Davidson. &amp;lt;ref&amp;gt;[http://web.archive.org/web/20130212081001/http://mycorner.no-ip.org/6502/shorts/range.html Lee Davidson's 6502 Shorts]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;/div&gt;</summary>
		<author><name>MSaarna</name></author>	</entry>

	</feed>