Sean wrote:
It seems to me that large blocks of assembly code used in multiple places should be written as subroutines, and short blocks of code that are repeated frequently should be macros. I reasoned this is so because I don't want to needlessly duplicate large blocks of code, so a subroutine makes sense for large blocks of code use in multiple places. For example, I have written as a subroutine my code to loop through a string and print characters to the console, and code to draw a collection of shapes to screen.
OTOH, subroutine calls have a bit of overhead associated with them, including moving data into correct registers or memory location in order to set arguments and deal with return values, so probably those should be macros. So I've written code for 16-bit addition and subtract, about sixteen bytes apiece, as macros.
Is my reasoning sound? Am I missing anything?
At the simple level, the trade-off is space vs. speed.
Use subroutines - compact code, but runs slower. Use Macros, then it runs faster but the code is bigger.
I use macros extensively in my BCPL VM environment as I want to make every cpu cycle count for as much as possible - however I have the luxury of lots of RAM. I'm even unwinding loops just to save a JMP in some places too - and that was initially by defining a macro then just repeating it 32 times until I realised my assembler (as65 from the cc65 suite) could auto repeat loops...
Cheers,
-Gordon
_________________
--
Gordon Henderson.
See my
Ruby 6502 and 65816 SBC projects here:
https://projects.drogon.net/ruby/