Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Segmentation fault(core dumped)

Status
Not open for further replies.

huseyinyagli

Programmer
Nov 16, 2001
2
0
0
TR
Program is running normally do the job but is killed at the end and I get this error message

a very simple example:

---asm.s
global OpenFile

section .text

OpenFile:
push ebp
mov ebp,esp

mov eax,5
mov ebx,[ebp+8]
mov ecx,0
int 80h

leave
ret

--------main.c
extern int OpenFile(const char *);


int main(int argc,char *argv[]){
int result = 0;
if(argc > 1)
result = OpenFile(argv[1]);

printf("%d\n",result);
return 1;
}

----makefile
try : main.o asm.o
gcc -o try main.o asm.o
main.o : main.c
gcc -c main.c
asm.o : asm.s
nasm -f elf asm.s
 
Presumably, your OS is not DOS.

What part crashed?

Incidentally, the ENTER and LEAVE instructions are considered obsolete...
"Information has a tendency to be free. Which means someone will always tell you something you don't want to know."
 
I've found my problem, its that I dont push-pop the registers that I'm modifying in the function...
 
No, that's not it. LEAVE pops off ebp from the stack. Better yet, forget about using LEAVE and ENTER, they're considered obsolete and downright dangerous. "Information has a tendency to be free. Which means someone will always tell you something you don't want to know."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top