Re: Libraries


[Prev][Next][Index][Thread]

Re: Libraries



On Sun, 12 Apr 1998 10:36:11 -0600, Nathan Ernst
<hermittwig@GEOCITIES.COM> wrote:
>This is probably a stupid question, but what exactly do the libraries do =
>for you in assembly?
>
>NE
Not a stupid question at all. The TI /z80 asm stuff is a bit new to
me, so I'm not sure I can answer the question as it might apply to TI
stuff. But I will attempt to explain within the context of the PC asm
environment (my background is primarily 80x86 asm). If I convey the
general concept well enough, perhaps you can apply it to the specifics
of your question.

In the PC environment (as in many others) there are several steps
involved in creating an executable program. Using asm, one must first
assemble the program, and then link edit the object that the assemble
created. The link edit process (linking) is where the libraries come
into play.

Libraries contain object modules (pre assembled subroutines) that
perform a given function. If, for example, I created a subroutine that
would take the value in a specific register and convert the it to
something else, placing the result in a memory area pointed to by the
value in another specific register, I could use this subroutine (CALL
it) anytime I needed to perform that function in any  program I write.
So why put that same source code in every program in which I use that
subroutine? The answer is, I don't need to.

If I take the source code for my subroutine, assemble it to an object
module, and then "catalog" it into a library, it will always be
available for my use. To use it in a program, I must tell the
assembler that the module (whatever its name) is an "external"
reference. That way, the assembler wont issue an error when it can't
find the source code that defines that module -- I've already told the
assembler not to expect that source code. Then, I just "call" that
subroutine from within my program and assemble the program to an
object file, as if nothing were missing. But if you call a module that
isn't there and the source isn't in the program, how can the program
run? Well, it can't. At least not yet.

Once I have assembled my program into an object file, I must link edit
(link) the object code. When I run the link editor (aka linker), I
must give it not only the name of the object file I wish to turn into
an executable program, but also the name of any libraries that contain
objects that I referenced as an external in the program source code.
When the linker runs, it will create an executable file, containing
the object code from the program code, as well as the object modules
it copied in from the library (or libraries). The linker will also fix
the address on the call statement. If you think about it, the
assembler had no idea where the module would wind-up, so it didn't
even try to put an address to the call (it usually just puts 0000 for
an address). The linker knows where it attached the module, so it goes
to the call statement and puts an address there.

In some cases, there is another step to creating an executable file
for the PC (to create com files), but it has nothing to do with
libraries, so let's leave that alone.

I hope this long winded explanation of libraries gives you the general
concept. How this applies to TI / z80 asm, I'm not sure. To the best
of my knowledge, there is no linkage necessary for TI asm files and I
don't think assemblers like Tasm support external references. But this
could be very wrong, since all this TI stuff is new to me. Perhaps
someone else can fill in the blanks for both of us...

Randy
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mailto:snapp@ais.net
http://www.cl.ais.net/snapp


References: