0

I try to read several elements from the keyboard, given as input into an array that i have the address loaded into the %edi register. I get a segmentation fault error as soon as i type the first input. The "nodes" variable is previously read using also scanf and i checked and the value of it it's correct. The temp variable is a .space type and i thought about using it to store the data into the array, sequencially. Thanks

set_array:    

cmp nodes, %ecx 
je array_sum

pushl $temp  
pushl $format
call scanf
popl %ebx
popl %ebx

movl temp, %ebx -> i think here is the problem but i don't know why
movl %ebx, (%edi, %ecx, 4)

inc %ecx
jmp set_array
  • `scanf` will not preserve `%ecx` for you according to calling convention. You should do that yourself. PS: learn to use a debugger. – Jester Jan 06 '23 at 12:11
  • Also, you can pass the correct element address to `scanf` directly so that you do not have to copy from `temp`. – Jester Jan 06 '23 at 12:22

0 Answers0