I have a problem working on stacks.
Say for example I am in a stack and I already used movl %esp, %ebp
If I make 2 local word-sized variables (subl $4, esp), whenever I go to movw $1, -2(%ebp) it triggers a segmentation fault. Why is that so? Also, are immediate values allowed to be passed directly to stack variables?
My code is:
movw $12, %ax
pushw %ax
call _function
exit:
movl $1, %eax
movl $0, %ebx
int $0x80
_function:
movl %esp, %ebp
subl $4, %esp
movw $2, -2(%ebp)
addl $4, %esp
ret $2
I assemble, link and run with:
as myfile.s -o myfile.o
ld myfile.o
./a.out
I'm on a 64-bit system.