I have trying to write a program in x86 and it's giving me segmentation fault. I have narrowed it down to this segment. Why is this giving a segmentation fault? I did the same thing without the program (that is write the same control flow) and there was no error
segment .bss
a resb 4
b resb 4
m resb 4
section .text
global _start ;must be declared for using gcc
toh :
pop eax
mov [a],eax
mov eax, 1
mov [b],eax
mov eax, [b]
push eax
ret
_start: ;tell linker entry point
mov eax,2
push eax
call toh
pop eax
mov [m],eax
mov eax,1
int 0x80
push eax; ret;
- you're literally settingeip
toeax
here. This is not what you want. The stack is not used to return values this way.