I first created a NASM FILE with this function as shown below
Code: Select all
[bits 32]
[section text]
x_Four equ 8
[global _func1]
_func1:
push ebp
mov ebp,esp
mov eax,[ebp+x_Four]
add eax,4
mov esp,ebp
pop ebp
ret
Code: Select all
extern unsigned int func1(unsigned int);
int main(void)
{
printf("Result = %i\n",func1(10));
return 0;
}
nasm -f coff test.asm
gcc -o test.exe testc.c test.o
and obtained an executable file test.exe(I'm using windows)on running this file i get the following
[tt]
Exiting due to signal SIGSEGV
Bounds Check at eip=000101c2
eax=00000000 ebx=0000834b ecx=00000000 edx=00000340 esi=0000005c edi=00000000
ebp=0008fb40 esp=0008fb28 program=C:\NASM\TEST.EXE
cs: sel=00a7 base=834bd000 limit=0009ffff
ds: sel=00af base=834bd000 limit=0009ffff
es: sel=00af base=834bd000 limit=0009ffff
fs: sel=0087 base=00011090 limit=0000ffff
gs: sel=00bf base=00000000 limit=0010ffff
ss: sel=00af base=834bd000 limit=0009ffff
App stack: [0008fb60..0000fb60] Exceptn stack: [0000fac0..0000db80]
Call frame traceback EIPs:
0x000101c2
0x00002e78
[/tt]
Pls help me out as i cant figure out whats wrong and I want to interface NASM and GCC.Thanx in advance.