I intend to do this in C:
#include
int main() {
int arr[5];
arr[0] = 5;
arr[1] = 0;
arr[2] = 1;
arr[3] = 3;
arr[4] = 4;
int max
I am having a segmentation fault on the very first instruction
movl $5, -20(%ebp)
.
You are not allocating any space on the stack for arr
(i.e.: int arr[5]
):
pushl %ebp
movl %esp, %ebp
subl $20,%esp //<--- memory allocation
In order to deallocate the memory allocated on the stack by restoring the previous stack frame, use the leave
instruction just before ret
.