Page 1 of 1

Q: How to invoke function in *.INC files?

Posted: Mon Aug 30, 2010 5:25 pm
by Developer
Hi again,

I hope Mike can answer this Q.

I make a *.INC file, and then I put %include "printoscrn.inc"
and I wrote

mov si, message ;Load the message into SI-register.
call printOnScrn ;Invoke the printOnScrn function located in "printonscrn.inc".
int 0x10 ;BIOS video interrupt.


BTW, shall I tell the NASM that I have an extern function somewhere else?

Please help me out, and explain how I shall invoke the function in the *.inc
and how INC files shall be structured.

Thanks!

Re: Q: How to invoke function in *.INC files?

Posted: Tue Aug 31, 2010 3:31 am
by Mike
Hello,

Because of the way *.inc files are included, if the function is defined in the *.inc file it can be invoked the same way as any other routine (using CALL). I do personally recommend a more structured approach however you must be careful as the boot loader in the series is flat binary.

Re: Q: How to invoke function in *.INC files?

Posted: Tue Aug 31, 2010 2:30 pm
by Developer
Mike wrote:Hello,

Because of the way *.inc files are included, if the function is defined in the *.inc file it can be invoked the same way as any other routine (using CALL). I do personally recommend a more structured approach however you must be careful as the boot loader in the series is flat binary.
Since you are the actual OS developer and Kernel guy, can't you provide me
with more in-depth details? Thanks!

Re: Q: How to invoke function in *.INC files?

Posted: Wed Sep 01, 2010 11:34 pm
by Mike
Hello,

%include in NASM works the same as #include in C. It copies the contents of the file to include directly into the file to be assembled with the %include directive. The end result is the same as if you just written all of the code in one file.

Because of this, you can access any defined label (variable or function) in your code without anything special needed. extern is only needed for declaring external symbol names which we dont have here.

This method was used in the boot loader provided by the series for simplicity. Larger boot loaders are typically more structured, where the core of the loader is written in a higher level language.