Author Topic: linking with objects modules  (Read 11303 times)

nobody

  • Guest
linking with objects modules
« on: October 10, 2004, 07:23:30 AM »
Hello.
I trying to make a program with two modules, a main (main.o) module and a second module (video.o).

video.o exports a simple function named set_video with [global set_video].

main.o uses [extern set_video].

My problem is how to make a executable main for call to the function set_video.

Thanks
Rafa

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: linking with objects modules
« Reply #1 on: October 13, 2004, 06:46:38 AM »
You don't say what OS... I'll assume dos, 'cause "set_video" gets complicated in Windows or Linux...

You don't say if you're passing a parameter to "set_video", or how. You probably want to - after you've changed video mode, it's polite to change it back before you quit (unless, of course, it's your intention to change it and leave it changed). You could pass the parameter on the stack, as a C program would - easiest thing would be to pass it in al. (despite the name "main", I'm assuming this is an "all asm" program you're shooting for - if C is involved, it'll add an underscore to "set_video"... you'll do "set_video(...);" in C, but "video.asm" needs it to be called "_set_video". You can automatically prepend an underscore to anything declared "global" or "extern" by adding "--PREFIX_" to the Nasm command line.)

You've got the "main thing" right by having "extern" in "main.asm", and "global" in "video.asm". "main.asm" should include the "..start" symbol (you want exactly one), and probably the stack segment. Now assemble 'em with "nasm -f obj main.asm" and "nasm -f obj video.asm". The command line to the linker depends on the linker, but something like "link main.o video.o" (assuming a 16-bit linker - the one with masm32 won't work), or "val main.o video.o", or "alink -oEXE main.o video.o" ought to work. If it *doesn't* link properly, pay close attention to *exactly* what the error message says - underscores and stuff - and you can probably figure out what's wrong. If all else fails... "post the code"...

Best,
Frank