From: SourceForge.net <no...@so...> - 2006-06-14 20:35:01
|
Bugs item #1506172, was opened at 2006-06-15 04:02 Message generated for change (Settings changed) made by dannysmith You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=102435&aid=1506172&group_id=2435 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. >Category: non-mingw Group: None >Status: Closed >Resolution: Works For Me Priority: 5 Submitted By: Jan Kechel (foadjok) Assigned to: Danny Smith (dannysmith) Summary: call library function from assembly Initial Comment: The following code crashes under windows XP, while it works properly with dos djgpp and linux gcc: --- cut prog.c --- #include <stdio.h> extern void PrintStrings(); unsigned int Exported; int main() { Exported = 0xdeadbeef; PrintStrings(); return 0; } --- end cut prog.c --- --- cut printstr.asm --- [BITS 32] ; Default is 32-bit code [GLOBAL PrintStrings] ; export label [EXTERN printf] ; external procedure [EXTERN Exported] ; external variable [SECTION .data] ; data segment VersionString db "Testversion 0.01",00h PrintTemplate1 db "VersionString = '%s'", 0ah, 00h PrintTemplate2 db "unsigned int Exported = 0x%08x",0ah,00h [SECTION .text] ; code segment PrintStrings: push ebp mov ebp, esp push dword VersionString push dword PrintTemplate1 ; pass parameters call printf ; call C function push dword [Exported] push dword PrintTemplate2 ; pass parameters call printf ; call C function mov esp, ebp pop ebp ret --- end cut printstr.asm --- To build the program we used: under linux: $ nasm -felf printstr.asm $ gcc -o prog printstr.o prog.c $ ./prog -> works fine version-numbers under linux: gcc version 4.0.4 20060507 (prerelease) (Debian 4.0.3-3) NASM version 0.98.38 compiled on May 17 2005 Tu build the program under windows and dos all exported variables and external functions must have a leading underscore (e.g. '_printf') > nasm -fcoff printstr.asm > gcc -o prog.exe printstr.o prog.c > prog -> crashes (general protection fault) version-numbers under windows: gcc -dumpversion: 3.4.2 NASM version 0.98 ---------------------------------------------------------------------- >Comment By: Danny Smith (dannysmith) Date: 2006-06-15 08:34 Message: Logged In: YES user_id=11494 The fine manual says use nasmw -f win32 if you want win32 objects. win32 objects havew PE COFF format, not standard COFF Danny ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=102435&aid=1506172&group_id=2435 |