Category:6502 Assembly: Difference between revisions
no edit summary
Puppydrum64 (talk | contribs) m (→Decimal Mode) |
Puppydrum64 (talk | contribs) No edit summary |
||
Line 211:
===Know Your Opcodes===
Of course you should know what each instruction does, but it's also very handy on the 6502 to know what their hex values are
<lang 6502asm>loop:
lda $2000,x ;3 bytes
bne continue ;2 bytes
jmp end ;3 bytes
continue:
;imagine this is a very long subroutine where branching isn't possible
end:
rts ;1 byte</lang>
It would take fewer bytes to do this:
<lang 6502asm>loop:
lda $2000,x ;3 bytes
bne continue ;2 bytes
rts ;1 byte
continue:
;imagine this is a very long subroutine where branching isn't possible
end:
rts ;1 byte</lang>
Unfortunately, almost all optimizations in assembly languages are at the expense of readability (probably the biggest reason why assembly isn't used as much these days), and this one is no exception. When programming in 6502 in particular you will find yourself committing all the taboos of modern programming, such as <code>BREAK</code>, <code>GOTO</code>, and sometimes even the dreaded, forbidden, <code>SELF-MODIFYING CODE!</code>
==Citations==
|