From: Tor H. <thu...@ho...> - 2003-02-18 21:41:20
|
>From: "Luke Dunstan" <cod...@ho...> >To: thu...@ho..., min...@li... >Subject: Re: [Mingw-users] problem calling C functions from nasm >Date: Thu, 13 Feb 2003 10:03:34 +0800 > > > > >From: "Tor Husabø" <thu...@ho...> > >To: min...@li... > >Subject: Re: [Mingw-users] problem calling C functions from nasm > >Date: Wed, 12 Feb 2003 22:53:19 +0100 > > > >here´s the source code: > > > >This is the C part: > > > >/* call_asm.c */ > > > >int asm_func(void); > > > >main() > >{ > > int return_from_malloc; > > > > return_from_malloc = asm_func(); > > printf("0x%08x\n", return_from_malloc); > > return 0; > >} > > > > > >This is the assembly part: > >; ASM_FUNC.ASM > >segment .text > >extern _malloc > >global _asm_func > > > >_asm_func: > > push dword 8 ;I'm not sure of the syntax to force the type > > call _malloc > > add esp, 4 > > ret > >; end of _asm_func > > > >Does this seem okay to you? I can´t see anything wrong with it myself... > >It works fine for me with these command lines: > >nasmw -f win32 asm_func.asm -o asm_func.o >gcc call_asm.c asm_func.o -o call_asm.exe >$ ./call_asm.exe >0x003f2bf0 > >Please note that the "win32" format is a slight variation of COFF (see the >nasm manual), so you DO need to use it, but in such a simple example it >_might_ not matter. The file names you gave here are different to your >original example, so did you confirm that this example actually crashes for >you? I tried nasm 0.98.22 with both GCC 3.2 and 3.2.2. If it does crash for >you then maybe you should try debugging it using GDB or at least a bunch of >printf statements. > >Luke > > > > > >>From: "Luke Dunstan" <cod...@ho...> > >>To: Tor Husabø ><thu...@ho...>,<min...@li...> > >>Subject: Re: [Mingw-users] problem calling C functions from nasm > >>Date: Mon, 10 Feb 2003 09:32:33 +0800 > >> > >> > >>----- Original Message ----- > >>From: "Tor Husabø" <thu...@ho...> > >>To: <min...@li...> > >>Sent: Monday, February 10, 2003 5:55 AM > >>Subject: [Mingw-users] problem calling C functions from nasm > >> > >> > >> > Has anyone succeeded in calling C functions from nasm routines? I use >nasm > >> > version 0.98.34 and mingw-gcc-3.2,. I assemble like this: nasm >caller.asm > >> > -f coff -ocaller.o, > >> > and then I say: gcc caller.o called_func.c -otestprog.exe. > >> > > >> > the asm routine is called from main(), and does nothing else than >calling > >>a > >> > c function, no arguments or anything. sorry I dont have the code >with ´me > >> > to show you, but it´s as simple as possible, both in C and asm. but >it > >> > crashes with no messages from winXP every time. the equvialent >routine > >> > written in GNU assembly works fine. What am I doing wrong? > >> > > >> > The guys at nasm.sourceforge.net wasn´t interested in this problem, >so > >> > please help! > >> > >>First try using "-f win32" instead of "-f coff", but otherwise I think > >>you'll have to show the nasm and C source code before anyone can >diagnose > >>your problem. You may also use GDB (5.2.1 preferably) to debug the >program. > >> > >>Luke > Ok, nasm with ´-f win´ did the trick. Guess I just haven´t noticed before that the files then get the extension '.obj' instead of just '.o', and used the same object files over again when I thought I used the ones assembled with '-f'. What a ridiculous mistake :) But thanks anyway, guys... _________________________________________________________________ MSN Messenger http://www.msn.no/messenger - Den korteste veien mellom deg og dine venner |