assembly program crashing

i am trying to learn assembly but it seems that it doesn't like me:
compiling and linking seems fine but this program crashes at runtime :

here is the error produced by windows ( if it really matters ) :

Problem Event Name: APPCRASH
Application Name: a.exe
Application Version: 0.0.0.0
Application Timestamp: 529c3e49
Fault Module Name: a.exe
Fault Module Version: 0.0.0.0
Fault Module Timestamp: 529c3e49
Exception Code: c0000096
Exception Offset: 00001412


and these are the files

hello.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
%include "asm_io.inc" ;-- author's header

segment .data
    outtext1 db 'Hello World', 0

segment .text
    global _asm_main

_asm_main :
    enter 0, 0
    pusha

    ;-- print the actual text
    mov eax, outtext1
    call print_string ;-- print_string is a sub. made by the author

    popa
    mov eax, 0
    leave
    ret 


driver.c
1
2
3
4
5
int main ()
{
    int i = asm_main();
    return i;
}


commands i typed :

> nasm -f coff hello.asm
> gcc driver.c hello.o asm_io.o
Instead of coff format, try elf (even if you're on Windows).

My commands (files taken from djgpp-ex.zip):

nasm -f elf asm_io.asm
nasm -f elf hello.asm
gcc -c driver.c
gcc asm_io.o hello.o driver.o


driver.c
1
2
3
4
5
6
7
8
9
10
#include "cdecl.h"

int PRE_CDECL asm_main( void ) POST_CDECL;

int main()
{
  int ret_status;
  ret_status = asm_main();
  return ret_status;
}
thanks Catfish, i've tried the elf format and it worked !! haha tnx !!!
Indeed it is awkward that the "native" formats (COFF, Win32) do not work.

Anyway, you made a good choice in Carter's book, I still think it's one of the best books to learn x86 Assembly from.
haha, yes it's really irritating , i've just read that elf format is used for linux.
and yes, the book is very detailed, i think i'm gonna have some headache and fun learning asm.
Topic archived. No new replies allowed.