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

If you are new to OS Development, plan on spending some time here first before going into the other forums.

Moderator:Moderators

Post Reply
Developer
Posts:37
Joined:Sun May 30, 2010 4:30 pm
Q: How to invoke function in *.INC files?

Post by Developer » Mon Aug 30, 2010 5:25 pm

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!

User avatar
Mike
Site Admin
Posts:465
Joined:Sat Oct 20, 2007 7:58 pm
Contact:

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

Post by Mike » Tue Aug 31, 2010 3:31 am

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.
Lead Programmer for BrokenThorn Entertainment, Co.
Website: http://www.brokenthorn.com
Email: webmaster@brokenthorn.com

Developer
Posts:37
Joined:Sun May 30, 2010 4:30 pm

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

Post by Developer » Tue Aug 31, 2010 2:30 pm

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!

User avatar
Mike
Site Admin
Posts:465
Joined:Sat Oct 20, 2007 7:58 pm
Contact:

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

Post by Mike » Wed Sep 01, 2010 11:34 pm

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.
Lead Programmer for BrokenThorn Entertainment, Co.
Website: http://www.brokenthorn.com
Email: webmaster@brokenthorn.com

Post Reply