Category:6502 Assembly: Difference between revisions

no edit summary
No edit summary
Line 215:
 
The second version takes an additional command per loop for no added benefit. Sometimes you may need X to represent something else in addition to the loop counter, or you may have a large amount of data from an external source, which would take a lot of time to manually reverse the order of the entries. In those cases it may be better to take the "branch penalty" as-is.
 
===Order Of Importance===
This concept is related to the one above. If you are implementing your own flags variable in software for controlling the execution of some function, bits 7 and 6 (the leftmost two bits) are the easiest to check. The 6502 does not have the same "bit test" command that is seen on the 68000, z80, 8086, or ARM. The 6502's <code>BIT</code> command can quickly check the value of bits 7 or 6 of a number stored in memory, but the other bits take longer since you have no choice but to load that variable into the accumulator and <code>AND</code> it with a bit mask.
 
</lang 6502>softwareFlags equ $00
 
;check bit 7
BIT $00
BMI bit7set
 
BIT $00
BVS bit6set
 
LDA $00
AND #%00100000
BNE bit5set
 
LDA $00
AND #%00010000
BNE bit4set
 
;etc</lang>
 
The moral of the story is, since two of the flags are easier to check than the rest, the ones that need to be checked the fastest or most frequently should be flags 7 or 6.
 
 
===Know Your Opcodes===
1,489

edits