Thread: Linking an assembly routine into a GCC project

  1. #1
    Registered User
    Join Date
    Nov 2002

    Question Linking an assembly routine into a GCC project

    (Sorry if this is a common topic or is in the wrong board ive tried searching to no solution)

    I have the below assembly routine (computes e^X - 58 cpu clock cycles on an athalon - I would be impressed if someone could find a faster routine ) written in MASM syntax, and I no matter what I try I cannot manage to be able to use it from my C++ source.

    I have declared:
    -e_pwX PROTO : DWORD (In Assembly Source)
    -PUBLIC e_pwX
    -extern void e_pwX(FLOAT *); (In C++ Source)

    And assembled the assembly source into a (COFF) object binary and included this file in the linker command line but when trying to compile I get this error:

    [Linker error] undefined reference to `e_pwX(float *)'

    My somewhat limited understanding of C++ doesn't help either but I will be grateful for any suggestions.


    The routine:
    e_pwX PROC C lpFloat: DWORD
    fld [lpFloat]
    sub     esp,16
    fmul                                  ; z = x*log2(e)
    fist    DWORD PTR [esp+12]            ; round(z)
    fstp    TBYTE PTR [esp]
    fisub   DWORD PTR [esp+12]            ; z - round(z)
    mov     eax, [esp+12]
    add     [esp+8],eax
    fadd                                  ; 2^(z-round(z))
    fld     TBYTE PTR [esp]               ; 2^(round(z))
    fmul                                  ; 2^z = e^x
    add     esp,16
    fst [lpFloat]
    e_pwX ENDP

  2. #2
    C > C++ duders ggs's Avatar
    Join Date
    Aug 2001
    I haven't used any assembly code in gcc (or used masm style syntax, for that matter), but you could try declaring it as extern "C" instead of just regular extern. If it's C++, i think the function name will get mangled about in odd ways. If that doesn't solve it, i'm sorry :/
    .sect signature

  3. #3
    Registered User
    Join Date
    Nov 2002
    Cheers, using extern "C" worked a charm and now I everything compiles fine.

  4. #4
    Registered User moi's Avatar
    Join Date
    Jul 2002
    edit: n/m
    hello, internet!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. HELP: assembly & C linking woes....
    By andrewwan1980 in forum Tech Board
    Replies: 4
    Last Post: 09-28-2007, 04:17 PM
  2. Project details: Dedicated
    By Stack Overflow in forum Projects and Job Recruitment
    Replies: 9
    Last Post: 02-22-2005, 03:10 PM
  3. gcc
    By DavidP in forum A Brief History of
    Replies: 21
    Last Post: 10-22-2003, 03:46 PM
  4. gcc 3.2 & linking
    By rotis23 in forum Linux Programming
    Replies: 1
    Last Post: 06-23-2003, 06:46 AM