Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How can I link assembler to __fastcall C functions?

157 views
Skip to first unread message

Mark Grinnell

unread,
Mar 5, 2000, 3:00:00 AM3/5/00
to

I'm having trouble calling a C function defined as __fastcall from my
assembly code. I'm clear on how the calling convention works, but I can't
get the linker to link to it correctly. For example,

quick.h
int Alloc( int size );
int __fastcall QuickAlloc1( int size );
int __fastcall QuickAlloc2( int size );
call.asm
.CODE
extrn Alloc:near
extrn QuickAlloc1:near
extrn @QuickAlloc2@4:near
...
call Alloc
call QuickAlloc1
call @QuickAlloc2@4
...

Linker reports
error LNK2001: unresolved external symbol _QuickAlloc1
error LNK2001: unresolved external symbol _@QuickAlloc2@4

I don't know how to tell ml to decorate the function name properly for me,
and it won't even let my do it myself because it insists on doing the
"normal" C function name mangling of prepending the _ character. Does
anyone know how to do this right? I'm using Microsoft VC++ 6.0 and Microsoft
ml.exe 6.14.8444.

Thanks,
Mark


Daniel M. Pfeffer

unread,
Mar 5, 2000, 3:00:00 AM3/5/00
to

"Mark Grinnell" <MarkGr...@usa.net> wrote in message
news:sc41d0...@corp.supernews.com...

try

extrn C Alloc: proc
extrn fastcall QuickAlloc1: proc
extrn fastcall QuickAlloc2: proc


Daniel Pfeffer.


Mark Grinnell

unread,
Mar 6, 2000, 3:00:00 AM3/6/00
to

Daniel M. Pfeffer <pfef...@nospam.internet-zahav.net> wrote in message
news:sc56o0d...@corp.supernews.com...

>
> "Mark Grinnell" <MarkGr...@usa.net> wrote in message
> news:sc41d0...@corp.supernews.com...
> >
> > I'm having trouble calling a C function defined as __fastcall from my
> > assembly code.
>
> try
>
> extrn C Alloc: proc
> extrn fastcall QuickAlloc1: proc
> extrn fastcall QuickAlloc2: proc
>
> Daniel Pfeffer.
>

What assembler/version do you use? I copied your code into my file, but I
get:
D:\os63\W32\C\ASM>ml -c -Cp -Zd /coff interp.asm
Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997. All rights reserved.

Assembling: interp.asm
interp.asm(578) : error A2008: syntax error : QuickAlloc1
interp.asm(579) : error A2008: syntax error : QuickAlloc2

Thanks,
Mark


Daniel M. Pfeffer

unread,
Mar 6, 2000, 3:00:00 AM3/6/00
to

"Mark Grinnell" <MarkGr...@usa.net> wrote in message
news:sc6egf...@corp.supernews.com...

I was using an older version of MASM. Using MASM 6.11, the following file
compiled correctly.


.386
.model flat

.code

Alloc1 proc C
ret
Alloc1 endp

@Alloc2 proc
ret
@Alloc2 endp

end


Note that there is no language defined in the .model statement, so when a
C-style procedure is desired - you must explicitly specify the language in
the 'proc' statement.


Daniel Pfeffer


Mark Grinnell

unread,
Mar 10, 2000, 3:00:00 AM3/10/00
to

> > Daniel M. Pfeffer <pfef...@nospam.internet-zahav.net> wrote in message
> > news:sc56o0d...@corp.supernews.com...
> > >
> > > "Mark Grinnell" <MarkGr...@usa.net> wrote in message
> > > news:sc41d0...@corp.supernews.com...
> > > >
> > > > I'm having trouble calling a C function defined as __fastcall from
my
> > > > assembly code.
> > >
> > > try
> > >
> > > extrn C Alloc: proc
> > > extrn fastcall QuickAlloc1: proc
> > > extrn fastcall QuickAlloc2: proc
> > >

FYI, using SYSCALL is the way to go here, e.g.
extrn syscall @QuickAlloc1@4:near
generates instructions to the linker to use the func name exactly as
specified and not decorate it.


0 new messages