Category:6502 Assembly: Difference between revisions

Content added Content deleted
No edit summary
Line 225: Line 225:
===Looping Backwards Is Faster===
===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.
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>
<lang 6502asm>LDX #3 ;set loop counter to 3.
LDX #3 ;set loop counter to 3.
loop:
loop:
;whatever you want to do in a loop goes here
;whatever you want to do in a loop goes here
Line 233: Line 232:


compared to:
compared to:
<lang 6502asm>
<lang 6502asm>LDX #0 ;set loop counter to 0.
LDX #0 ;set loop counter to 0.
loop:
loop:
;whatever you want to do in a loop goes here
;whatever you want to do in a loop goes here