flat assembler
Message board for the users of flat assembler.

Index > Main > problems with linking C with FASM

Author
Thread Post new topic Reply to topic
decard



Joined: 11 Sep 2003
Posts: 1092
Location: Poland
decard
Recently some people were asking about linking C objects with FASM code. I was making some experiments, but I met some problems when I was trying to call some C routine inside assembly source. See:

c source:
Code:
#include <stdio.h>

extern int multiply(int,int);

void ppp()
{
 printf("dsadasd");
}

int main()
{
  int result;
 result = multiply(0, 0);
    printf("the result is: %d", result);
  return 0;
}    


assembly source:
Code:
format COFF
include "%fasminc%/macro/cdecl.inc"

public multiply as "_multiply"
extrn "_ppp" as ppp:dword


section '.text' code

cproc multiply, a,b
        enterc
        push    edx
        call    ppp
        mov     eax,[a]
        mov     edx,[b]
        mul     edx
        pop     edx
        retc    


and it produces very strange results. What's wrong? Maybe it is me that does something in a wrong way?Confused

regards
Post 26 Feb 2004, 22:50
View user's profile Send private message Visit poster's website Reply with quote
Vortex



Joined: 17 Jun 2003
Posts: 318
Vortex
Which C compiler are you using?

To use Fasm with MS VC++ , have a look at:

http://board.flatassembler.net/topic.php?t=1095

_________________
Code it... That's all...
Post 02 Mar 2004, 10:51
View user's profile Send private message Visit poster's website Reply with quote
decard



Joined: 11 Sep 2003
Posts: 1092
Location: Poland
decard
Actually I'm using GCC. But I will take a look, maybe I will find some solution Wink
Post 02 Mar 2004, 11:45
View user's profile Send private message Visit poster's website Reply with quote
decard



Joined: 11 Sep 2003
Posts: 1092
Location: Poland
decard
Hi Vortex,
The problem is that in your code assembly module doesn't require any C function. I have no problem when calling asm from C, but I can't make it work in "both ways".

regards
Post 02 Mar 2004, 15:43
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.