Click to See Complete Forum and Search --> : combining c and assembly


vertex78
January 17th, 2009, 04:07 PM
Hello, I am going through Paul Carter's assembly tutorial and I am having troubles compiling the first example. There error message I get is:

example1.o: file not recognized: File format not recognized
collet2: ld returned 1 exit status


Here is my c code and my assembly code.


#include <stdio.h>

int main(){
asm_main();
return 0;
}



segement .data
segment .bss
segment .text
global _asm_main
_asm_main:
enter 0,0
pusha

popa
mov eax,0
leave
ret


To compile I did:

nasm -f coff example1.asm
gcc -o example1.o main.c


I am using linux and gcc version 4.3.2

saeedIRHA
January 27th, 2009, 09:50 AM
first compile the main.c file with this command:

gcc -c main.c


then link all the object files with this command:

gcc -o output example1.o main.o