Linking an assembly routine into a GCC project

This is a discussion on Linking an assembly routine into a GCC project within the C++ Programming forums, part of the General Programming Boards category; (Sorry if this is a common topic or is in the wrong board ive tried searching to no solution) I ...

  1. #1
    huh
    huh is offline
    Registered User
    Join Date
    Nov 2002
    Posts
    5

    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.

    -Cheers



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

  2. #2
    ggs
    ggs is offline
    C > C++ duders ggs's Avatar
    Join Date
    Aug 2001
    Posts
    435
    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
    huh
    huh is offline
    Registered User
    Join Date
    Nov 2002
    Posts
    5
    Cheers, using extern "C" worked a charm and now I everything compiles fine.

  4. #4
    moi
    moi is offline
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    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, 02:10 PM
  3. gcc
    By DavidP in forum A Brief History of Cprogramming.com
    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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21