extern puts
extern printf
section .rodata
format db "%u ", 0
puts_format db "", 0
section .data
arr1 dd 10, 20, 30, 40, 50, 60, 70, 80
len1 equ 8
arr2 dd 11, 22, 33, 44, 55, 66, 77, 88, 99
len2 equ 9
int_fmt db "%d ", 0
newline_fmt db 10, 0
section .bss
dest resd 10
section .text
global main
print_arr:
push ebp
mov ebp, esp
; TODO a: Implement array printing function:
; print_arr(unsigned int *arr, unsigned int len);
mov eax, [ebp + 8] ; eax = len
mov ebx, [ebp + 12] ; ebx = arr
mov ecx, 0
print_loop:
cmp ecx, eax
jge print_end
mov edx, ecx
imul edx, 4
push dword [ebx + edx]
push format
call printf
add esp, 8
inc ecx
jmp print_loop
print_end:
push newline_fmt
call printf
add esp, 4
leave
ret
main:
push ebp
mov ebp, esp
; Print arr1 using print_arr.
push dword len1
push arr1
call print_arr
add esp, 8
; Return 0.
xor eax, eax
leave
ret
After using the DBG, the SEGFAULT occurs at this line:
push dword [ebx + edx]
I don't know where the issue may come from or how to fix it. I'm thinking that one of the registers goes in an unallocated space in memory, but I don't know the cause of it.