Thread: Linking functions from .ASM file

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    329

    Linking functions from .ASM file

    Hello.
    I've got to link some functions from an assembly file, but i can't seem to make it work. I'm using Watcom IDE 11.0(c compiler/assembler). Here's an example of how i do it:

    // Prototype
    extern void _inton(void);

    // asm code
    .model large,c
    .code
    _inton proc
    sti
    ret
    _inton endp
    end

    When i try to compile it, i get an undefined reference.
    I don't understand why?

  2. #2
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    I think watcom was one of those stupid compilers that forced to link assembly code and c code while compiling them. My first suggestion would be get a new compiler. My more realistic suggestion would be to compile the .asm and .c at the same time. I notice that your assembler code is 16bit and doesn't do much. Watcom isn't win32 only is it?

  3. #3
    Blank
    Join Date
    Aug 2001
    Posts
    1,034
    Every assembler has a different syntax for this
    but are you making sure the label is global. On gas
    you would do
    .globl _inton

  4. #4
    knutso
    Guest

    Unhappy Assembly->C

    What i want to do, is to turn off the interrupts, and then enable them again when i'm done. Here's the assembly code:

    Code:
    .model large,c
    .code
    
    _inton proc
            sti
            ret
    _inton endp
    
    _intoff proc
            pushf
            pop ax
            cli
            ret
    _intoff endp
    
    _intrst proc flag:word
            mov ax,flag
            push ax
            popf
            ret
    _intrst endp
    
    _nop proc
            ret
    _nop endp
    end
    And then the C prototype(The compiler adds the underscore prefix, tried several variants of this):
    Code:
    extern unsigned short cdecl intoff();
    When i try to use any of the assembly functions, i get the following errors:
    Error! E2028: _intoff is an undefined reference
    file com.obj(C:\_src\cpp\Test\com.c): undefined symbol _intoff

    Any suggestions/other compilers/assemblers i could try?

  5. #5
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793

    Re: Assembly->C

    I've never worked with Watcom, but I have use MASM with VC++...

    The gotcha that was giving me problems was that MASM defaulted to STDCALL and VC++ defaulted to the C calling convension..as soon as I declared the external func with the proper calling conevnsion, it worked....

    No idea though if this relates at all to what your doing........

  6. #6
    knutso
    Guest

    Cool Figured it out

    The assembly functions had to be declared public:
    Code:
    public	__inton
    __inton proc

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems passing a file pointer to functions
    By smitchell in forum C Programming
    Replies: 4
    Last Post: 09-30-2008, 02:29 PM
  2. Help on simple file functions
    By enjoyincubus in forum C Programming
    Replies: 20
    Last Post: 12-01-2006, 04:41 AM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  4. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 03:39 AM
  5. Replies: 4
    Last Post: 10-21-2003, 04:28 PM