This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Using a library to call a preassembled .obj file

I will try this again!! Surely there must be some one out there who can answer this question directly. I have written two files for a probject give below:

;Main Program (separate file)

extrn code (_test1)

cseg at 0

ljmp _start

main segment code
rseg main

_start:
lcall _test1
stop: sjmp stop
end

;program test1 (separate file)

public _test1

test1 segment code
rseg test1

_test1:
mov a,#99h
mov r0,a
ret
end

These two files are set up in a project and they work by calling test1 and moving 99h into the accumulator.

Now.....I would like to put test1.obj in a library file. For example, Mylibrary.

Now I would like to remove the _test1 file from my project and reference _test1 from my libray. What code do I use in the main program so that I can properly call the subroutine _test1?

Does any one out there understand my question and can directly answer it?

Thank you so much.

Jim Gilliam

  • Step 1: Actually create the library. See Chapter 10 of the "Macro Assembler and Utilities" manual for how, or just select option "create a library" on the "Output" tab of the target options of a new target that has test1.asm as its only source file.

    Step 2: Create a header file for it; let's call it "test.inc". The most important part of that header file will be a line like this:

    EXTRN CODE (_test1)
    

    which tells the compiler that "_test1" is defined somewhere.

    Step 3: Add the generated library from step 1 to the list of inputs for the "main" target, and add a line

    INCLUDE "test.inc"
    

    to main.asm to access the header file from step 2.

    If this doesn't work, you really should get from asking vague questions to providing some usable details, such as: *What* did you actually try, and *how* exactly did it fail?

  • A little self-correction needed: make that include line

    $INCLUDE (test1.inc)
    

    FWIW: I just went through this exercise here, for the fun of it. Worked like a charm.

  • How does the header file test.inc know to look in the library file named mylibrary that contains the file _test1.obj? It would seem to me that somewhere I would have to tell either main or test.inc which library to look in?

    Jim

  • I guess my problem is I am having a real hard time understanding you step 3. How do I add the library to the list of inputs. What inputs? God I am having so much trouble understanding this.

    Jim

  • I suppose you don't need to add any include files since the declaration of _test1 is already present in your code:

    extrn code (_test1)
    
    To learn how to add a library to a project, follow this link:
    http://www.keil.com/support/docs/147.htm
    There are other useful articles in the Keil Support Knowledgebase, you might want to have a look:
    http://www.keil.com/support/

    - Mike

  • > How do I add the library to the list of inputs. What inputs?

    Well, you go to the project browser, select "Add Files to Group...".

    In the file dialog box, select "Library files" in the bottom selector, then select the library from the list. Click "Add", then "Close".
    Rebuild your "main" target and see.

    In larger projects, you may want to create a separate source group "Libraries" to hold these entries.

  • > How does the header file test.inc know to look in the library file named
    > mylibrary that contains the file _test1.obj?

    It doesn't. You have to do that yourself.

    This is one of the key differences between C / Assembly on one hand, and more "module-centered" ones like Pascal, Modula or Java. In C/Asm, using code from some other module or library always requires two steps:

    *) Adding the actual module to the list of things to be linked.

    *) Adding the interface declaration to the source files using it.

    A usable library thus always consists of at least two files that belong together: the object files (or library collecting them), and the header.