Category:6502 Assembly: Difference between revisions

m
No edit summary
Line 225:
===Looping Backwards Is Faster===
Looping is generally faster if the loop counter goes down rather than up. This is because <code>DEX</code> and <code>DEY</code> set the zero and negative flags if their value is zero or #$80 or greater. Generally speaking, this means that when your loop counter goes down, you don't have to use the <code>CMP</code> command to determine if the end of the loop is reached.
<lang 6502asm>LDX #3 ;set loop counter to 3.
LDX #3 ;set loop counter to 3.
loop:
;whatever you want to do in a loop goes here
Line 233 ⟶ 232:
 
compared to:
<lang 6502asm>LDX #0 ;set loop counter to 0.
LDX #0 ;set loop counter to 0.
loop:
;whatever you want to do in a loop goes here
1,489

edits