To include or not to include?

For general and site related discussion.

Moderators: XtC, BuZz

Post Reply
Zeb
Posts: 48
Joined: Sun Sep 09, 2007 10:59 am

To include or not to include?

Post by Zeb »

All my past assembler never used includes - values (including those pertaining to library functions) were hardcoded into the source.

Just writing a PCHG palette ripper tool in assembler and using includes for the first time but now instead of taking a couple seconds to assemble, it's now taking about 35.

Any real reason why includes should be used?

kyz
Posts: 126
Joined: Thu Nov 14, 2002 1:58 am
Location: Edinburgh, Scotland
Contact:

Re: To include or not to include?

Post by kyz »

Zeb wrote:All my past assembler never used includes - values (including those pertaining to library functions) were hardcoded into the source.

Just writing a PCHG palette ripper tool in assembler and using includes for the first time but now instead of taking a couple seconds to assemble, it's now taking about 35.

Any real reason why includes should be used?
Because you're wasting your time copying equates out of their source include files - it's a lot of hard work, it's risky and it puts you off using "new" equates.

For writing a demo, you only need a few equates from the include files for the OS and the rest for the custom registers, then you never need any more. For a large program like a GUI you may well abandon writing code because there are so many library calls, structure offsets, bitfields and values to copy out that you just get fed up of it half-way through writing your program and you abandon it.

Any value you copy by hand (or trying to memorise it) you risk getting it wrong, spending hours trying to debug your code until you discover the fault that you had written LN_NAME=8 when it's actually 10. It's deceptive because move.l LN_NAME(a1),a0 doesn't look wrong.

Or, alternatively, you may avoid using the correct names for things and just use the raw numbers. Then you wonder when you look back at your code later what the hell move.l 10(a1),a0 / lea 22(a0),a0 actually means and you find it impossible to keep writing it without spending lots of time reverse-engineering your undocumented intentions and assumptions. Discipline in writing code in a structured and documented way seems like a waste of time when you start off writing code, but it's the reason WHDLoad is still being written whereas JST stopped being written years ago. I looked at the code of both: WHDLoad is well written, while JST is a complete mess and I thought (a year or so before JOTD stopped writing it) that "this is soon going to be impossible to modify or change, because so many unrelated pieces of code depend on each other and will break when you change the smallest part of any of them".

As for taking 35 seconds to assemble, it sounds like
* you are developing on a floppy-only machine
* you are including unnecessary include files
* you are not using a good assembler.

If you are developing on a floppy-only machine, put the includes in an lha/lzx archive and extract them to RAM: on bootup, then assemble using the includes from RAM.

Don't include unnecessary include files. If you include exec/libraries.i, that automatically includes exec/nodes.i and exec/types.i. Demanding an include file gets included twice only wastes time, as the assembler really does have to include it again, and because of the anti-include-twice protection, it adds nothing new.

Finally, if you use ASMOne or Devpac 3, they both support various speed-up mechanisms for includes. Personally, I use PhxAss, and I break my large code down into separate modules which I then link together to create executable(s). I use a Makefile, which ensures I just have to type "make" and it only assembles code I've actually changed, while leaving all the other code compiled and ready to link.

Regards
Stuart

Zeb
Posts: 48
Joined: Sun Sep 09, 2007 10:59 am

Post by Zeb »

Thanks kyz, I'm extremely impressed with your reply and so much makes sense.

I'm running DevPac 3.18 on WinUAE on my PC with 2MB Chip, 8MB Fast. My CPU is AMD Athlon x2 Dual Core at 2.6GHz with a high end motherboard and slightly above midrange graphics card.

I think my problem is including includes twice somewhere, I'll take some out and try again.

It's funny because the actual source is around 900 lines of code yet 12000+ assemble :lol:

Post Reply