I want to write into an array using input from a keyboard. I am using a loop to do this but it gives me a 'Segmentation fault (core dumped)' error. I don't really understand how am i supposed to do it. Here is the relevant code:
.data
array: .space 400
array_len: .space 4
inputFormat: .asciz "%d"
.text
.global main
main:
pushl $array_len
pushl $inputFormat
call scanf
popl %ebx
popl %ebx
xorl %ecx, %ecx
lea array, %edi
l_loop:
cmp %ecx, array_len
je l_exit
pushl %eax
pushl $inputFormat
call scanf
popl %eax
popl %eax
molv %eax, (%edi, %ecx, 4)
incl %ecx
jmp l_loop
...
I figured out that the problem comes from the line:
movl %eax, (%edi, %ecx, 4)
in the (%edi, %ecx, 4) part
I tried changing the (%edi, %ecx, 4) part to something else (like %ebx) and it worked. Also, everything works well when i comment that line. Am i missing something?