Assembler: crash at function call.
category: general [glöplog]
Hello.
I've recently stared learning 80x86 assembly language with this tutorial. And I have a little problem with function calls. Everytime I do a function call my program crashes. And the strange thing is that the author's asm examples crashes as well.
I'm using NASM and MinGW's gcc.
What I do is:
driver.c
test.asm
And the build commands are:
So... what's wrong with it?
Thanks for any help.
I've recently stared learning 80x86 assembly language with this tutorial. And I have a little problem with function calls. Everytime I do a function call my program crashes. And the strange thing is that the author's asm examples crashes as well.
I'm using NASM and MinGW's gcc.
What I do is:
driver.c
Code:
int asm_main();
int main(int argc, char *argv[])
{
int status = asm_main();
return status;
}
test.asm
Code:
segment .data
msg1 db "printf() test!",0
format db "%s",0
segment .bss
segment .text
global _asm_main
extern _printf
_asm_main:
enter 0,0
pusha
push dword msg1
push dword format
call _printf
pop ecx
pop ecx
popa
mov eax,0
leave
ret
And the build commands are:
Code:
C:\asm>gcc -c driver.c
C:\asm>nasm -f coff test.asm
C:\asm>gcc -o test.exe driver.o test.o
So... what's wrong with it?
Thanks for any help.
Code:
gcc -c driver.c
nasm -f win32 test.asm
gcc -o test.exe driver.o test.obj
Thanks a lot! :) I didn't notice I was using wrong object format.
microsoft says they're using COFF format, but in reality it's not COFF format. Got me once badly when I was porting the System16 emulator from DOS to Windows. Had to write a tool to convert assembler sources from GNU syntax to Nasm/Intel syntax.
The mean thing about this incompatibility is that no part of the toolchain (even MSVC) complains, and then when running the code the relocs are totally messed up...
cheers
The mean thing about this incompatibility is that no part of the toolchain (even MSVC) complains, and then when running the code the relocs are totally messed up...
cheers