Author Topic: Compiling subroutines only when needed  (Read 504 times)

Offline RuudB

  • Jr. Member
  • *
  • Posts: 32
  • Country: nl
    • Ruud's Commodore Site
Compiling subroutines only when needed
« on: March 03, 2019, 10:16:24 AM »
Hello,

When programming in Turbo Pascal/FreePascal I use a "unit" that contains various subroutines of my own. When compiling a program only those subroutines are compiled that are called. I think it is possible in MASM/TASM by creating a LIBrary but I prefer using NASM of course :)

So far I copied the needed routines into my programs but recently I found a bug and that meant I had to go through all sources to repair it. It would be handy to repair such a bug at one place only.

Of course I did some RTFM and found some things that should do the same trick on page 98: the directive LIBRARY and RDF files. But so far I haven't found any example that could show me how to use them. Any example or an URL with examples and/or explanation would be very welcome.

Thank you very much in advance!
With kind regards / met vriendelijke groet, Ruud Baltissen

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2373
  • Country: us
Re: Compiling subroutines only when needed
« Reply #1 on: March 06, 2019, 10:20:12 PM »
Hi Ruud,

I would advise you against "-f rdf". I think it's broken currently anyway. The only reason Nasm includes the "library" utility is that it's a "homemade" output format and such tools don't exist anywhere else in the world. I don't think it's what you want.

Just put your Nasm code in a separate file. "global" (I think Masm/Tasm calls it "public") uells Nasm to tell the linker that the code is in this file - make it available elsewhere. "extern" tells Nasm to tell the linker that the code is used here, but exists elsewhere. After that, it's up to the linker. You Probably find "lib.exe" with the linker. In the Linux environment, you'd use "ar" to create a library.

You sometimes use "-f bin". You can't make a library, but you can still do something like:
Code: [Select]
jmp start
%include "read.asm"
%include "write.asm"
; etc.
start:
call write
;etc.
;...
if you want your code in separate files.

Hope this helps...

Best,
Frank



Offline RuudB

  • Jr. Member
  • *
  • Posts: 32
  • Country: nl
    • Ruud's Commodore Site
Re: Compiling subroutines only when needed
« Reply #2 on: March 07, 2019, 06:33:25 AM »
Hallo Frank,

Thank you for the pointers to "global" and "extern". If I find out how to make it work, I'll write something that can be read for dummies like me :)
I'll keep you updated anyway.
 
With kind regards / met vriendelijke groet, Ruud Baltissen

Offline RuudB

  • Jr. Member
  • *
  • Posts: 32
  • Country: nl
    • Ruud's Commodore Site
Re: Compiling subroutines only when needed
« Reply #3 on: March 07, 2019, 08:00:37 AM »
Bummer :(
EXTERN cannot be used with file of the type BIN and that is what I have been producing so far: old 16-bitters like COM, SYS and binaries like BIOSes.
With kind regards / met vriendelijke groet, Ruud Baltissen

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2373
  • Country: us
Re: Compiling subroutines only when needed
« Reply #4 on: March 07, 2019, 09:02:14 PM »
Hi Ruud,

Right, "-f bin" does not produce a linkable format. You can "%include" files, or if you want to assemble the separate files first, "incbin" should work. "global" doesn't work ether but is silently ignored - really should be an error or warning. I guess I didn't make that clear...

Best.
Frank

Offline RuudB

  • Jr. Member
  • *
  • Posts: 32
  • Country: nl
    • Ruud's Commodore Site
Re: Compiling subroutines only when needed
« Reply #5 on: March 08, 2019, 06:02:24 AM »
Hallo Frank,
You can "%include" files, ... I guess I didn't make that clear...
No, you made that very clear. The problem is, I already have this file with goodies. If I just pick the needed subroutine, the original COM is just a few hundred bytes. If I include the file with goodies, it becomes 19 KB. 19 KB doesn't sound much in this time but when having to work on a Commodore PC1 with just one 360 KB floppy drive, size does matter.

But just in case I did misunderstood you, I'm sorry and any help is welcome!
With kind regards / met vriendelijke groet, Ruud Baltissen