There's a thread over on Stardot where with some cooperative effort, some few hundred bytes are shaved off a 16k ROM program, to make room for more features.
There are several examples given of specific changes, including
- making use of 65C02 opcodes such as BRA and STZ
- changing JSR then RTS to a JMP
- changing JMP to BRA
- re-ordering routines to allow fall-through instead of JMP or BRA
- pulling common code into subroutines or jumping to common postambles
- inlining subroutines used only once
- rolling up repetitive code into loops
- reorganising loop code to use fewer operations
- removing unnecessary operations
- removing dead code
- making some not-so-important features conditionally included in the assembly
There may be nothing very new in there for experienced 6502 coders, but it might be worth a look. I know I enjoyed reading it through! If there are some more tactics not listed above which merit a mention, feel free to discuss them in this thread.
Also notable is the use of some automatic analysis to find opportunities - not quite automatic peephole optimisation but heading in that direction. (In this case a couple of Python scripts.)
Perhaps this is a good place to join the thread:
http://stardot.org.uk/forums/viewtopic. ... 44#p131544There are four flavours of the ROM being built - it's a filesystem for the BBC Micro, with drivers for one or more of several devices: floppy, IDE drive, bit-banged SD Card.
Another possible way to view the changes is to review the commits made in git.
https://github.com/ZornsLemma/ADFS/commits/masteror possibly this branch:
https://github.com/ZornsLemma/ADFS/commits/scratch2(You'll also see changes which improve the organisation, the labelling, or the commenting of the source, which is ultimately derived from a disassembly of an Acorn ROM.)
(The source format used is
BeebAsm, which allows for structured assembly coding. It would be nice if we could refrain from discussing syntax preferences in this thread! You might need to know that & introduces a hex number in this dialect.)
Hat-tip to hoglet for bringing this thread to my attention.