Newbie Question: extrn

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
TheDaneProgrammer
Posts: 1
Joined: Mon Jun 28, 2010 11:44 am

Newbie Question: extrn

Post by TheDaneProgrammer »

Hi OsDevers.

I'm new to OS Developing and Assembler, and I've never got the thing about extrn :oops:. What does it do, and what do I have to specify etc?

I couldn't find anything on Google.

Oliver
cyr1x
Member
Member
Posts: 207
Joined: Tue Aug 21, 2007 1:41 am
Location: Germany

Re: Newbie Question: extrn

Post by cyr1x »

It tells the assembler that the label is within a different object file.
This is necessary when you want to link several object files.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Newbie Question: extrn

Post by Combuster »

TheDaneProgrammer wrote:I've never got the thing about extrn :oops:.
It helps if you fix your spelling and search on "extern" instead :wink:
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
JohnWilson
Posts: 14
Joined: Wed Jun 23, 2010 11:08 pm

Re: Newbie Question: extrn

Post by JohnWilson »

Combuster wrote:It helps if you fix your spelling and search on "extern" instead :wink:
I'm guessing it depends on your assembler. I use TASM 5.0 (in MASM mode) and extern gives an error (just tried it) -- all my code uses extrn. But I suppose no one uses TASM any more.

Anyway to answer the OP in a tiny bit of detail, it goes something like this (um, in TASM/MASM, so YMMV if you're using NASM or something):

In one source file:

Code: Select all

foo:    public  foo
... does something ...
        ret
Then in another source file:

Code: Select all

        extrn   foo:near
        call    foo
There's other stuff for calling other languages but that's the basic form. The type can be "near" or "far" if it's a label for a subroutine, or one of the data sizes ("byte", "word", "dword" etc.) if it's the label of a variable, or various other things that you're less likely to need.

John Wilson
D Bit
Post Reply