HELP: assembly & C linking woes.... - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

HELP: assembly & C linking woes....

I am having problems linking an assembly object with my C object files. Am getting:

Linker Warning: DOSSEG directive ignored in module asm.asm
Linker Error: Undefined symbol _ASMClsV in module main.c
Linker Error: Undefined symbol VADDR in module asm.asm

In my asm.asm file I've got:

DOSSEG
.MODEL huge
.386

.DATA
EXTRN vaddr : word;

.CODE
PUBLIC ASMClsV

ASMClsV PROC Near
;bla bla
ASMClsV EndP

In main.c I've got:

extern void ASMClsV();

Am trying to link using Borland C++ 4.5 since my source files are all 16-bit. I successfully linked the same asm.asm file with a 16-bit pascal object using Turbo Pascal 7.0. Why can't I link using Borland C++ 4.5 to a 16-bit C file?

Also, I used Microsoft Macro Assembler 5. Should I use Turbo Assembler?


Comments

  • BitByBit_ThorBitByBit_Thor Posts: 2,444Member
    : I am having problems linking an assembly object with my C object
    : files. Am getting:
    :
    : Linker Warning: DOSSEG directive ignored in module asm.asm
    : Linker Error: Undefined symbol _ASMClsV in module main.c
    : Linker Error: Undefined symbol VADDR in module asm.asm
    :
    : In my asm.asm file I've got:
    :
    : DOSSEG
    : .MODEL huge
    : .386
    :
    : .DATA
    : EXTRN [color=Blue]_vaddr[/color] : word;
    :
    : .CODE
    : PUBLIC [color=Blue]_ASMClsV[/color]
    :
    : [color=Blue]_ASMClsV[/color] PROC Near
    : ;bla bla
    : [color=Blue]_ASMClsV[/color] EndP
    :
    : In main.c I've got:
    :
    : extern [color=Blue]"C"[/color] void ASMClsV();
    :
    : Am trying to link using Borland C++ 4.5 since my source files are
    : all 16-bit. I successfully linked the same asm.asm file with a
    : 16-bit pascal object using Turbo Pascal 7.0. Why can't I link using
    : Borland C++ 4.5 to a 16-bit C file?
    :
    : Also, I used Microsoft Macro Assembler 5. Should I use Turbo
    : Assembler?
    :

    C and C++ use name-mangling on variable and function names.
    C prepends an underscore (_) to each name, so "int main()" would become "int _main()" in ASM.
    However, C++ namemangling is MUCH worse than that. CppFunction would become something like ?CppFunction@@YAXXZ
    This is done to allow overloading functions in C++ - you can overload a function if it's overloaded 'decorated name' is different from the original.
    I am not sure how portable this is, but Microsoft's C++ compilers use:
    [code]
    extern "C" varC;
    // Will be mangled to _varC
    [/code]
    To use the old name mangling. This is what you'll want to specify for all functions and variables that need to be used in ASM.


    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry
  • andrewwan1980andrewwan1980 Posts: 16Member
    Excellent! I managed to get the C & assembly files recognise each others variables & functions. Thanks to Scorpions4ever for telling me about C mangles variable & function names by prefixing an underscore in front. Now I get a different problem:

    Linker Error: Fixup overflow at _TEXT:0002, target = vaddr in module asm.asm
    ...

    It appears there's a linker error line for each of my variables surrounded by [ ], eg.

    ASMClsV PROC Near
    mov es, [vaddr]
    ; bla bla
    ASMClsV EndP


    What does this Fixup overflow mean?
  • andrewwan1980andrewwan1980 Posts: 16Member
    I read the cool document about Fixup Overflow at http://vmlinux.org/~jakov/community.borland.com/15961.html but still unsuccessful. I fixed this problem myself by moving the variables from the C file to assembly file.

    C file:
    extern unsigned short vaddr; //Pascal word type
    extern long AsmY; //Pascal integer type
    extern void *ScrOfsPtr; //Pascal pointer type

    Assembly file:
    .DATA
    PUBLIC vaddr, AsmY, ScrOfsPtr
    vaddr label word
    AsmY label word
    ScrOfsPtr label dword


    Now I don't know why I need the label before word/dword. What does that mean? And is that correct corresponding to the C & Pascal types?
  • BitByBit_ThorBitByBit_Thor Posts: 2,444Member
    : I read the cool document about Fixup Overflow at
    : http://vmlinux.org/~jakov/community.borland.com/15961.html but still
    : unsuccessful. I fixed this problem myself by moving the variables
    : from the C file to assembly file.
    :

    Does the code work now?

    What I think you've done is create the 3 external labels in your own file. This will certainly eliminate any linker errors, but I don't think it'll produce the right code.
    I'm curious about the result (I might be wrong).

    PS: Who is 'Scorpions4ever'?

    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry
Sign In or Register to comment.