I'm trying to fill the array with the strings I have just converted from integers. Here's my code
segment .data
counter dd 9877
count dd 8642
array times 9876 dd '0000'
pointer dd 0
segment .bss
buffer resb 4 ; 4
segment .text
global _start
_start:
mov ecx, [count]
mov edx, array
mov dword [pointer], array
l1:
push ecx
push edx
dec dword [counter] ; decrease the counter
lea esi, [buffer]
mov eax, [counter]
call int_to_string
mov ecx, eax ; "begin print" position
xor edx, edx
getlen:
cmp byte [ecx + edx], 10
jz gotlen
inc edx
jmp getlen
gotlen:
inc edx
push eax ; printing the string converted
mov eax, 4
mov ebx, 1
int 0x80
pop eax ; printing the string converted
; copying the string to array
pop edx
mov [edx], eax
add edx, 4
pop ecx
loop l1
mov ecx, [count] ;printing the array
mov eax, array
l2:
push ecx
mov [pointer], eax
push eax
mov eax, 4
mov ebx, 1
mov ecx, pointer
mov edx, 4
int 0x80
pop eax
add eax, 4
pop ecx
loop l2
mov eax, 1
mov ebx, 0
int 0x80
int_to_string:
add esi, 9 ; counter + 9 ?
mov byte [esi], 10
mov ebx, 10
.next_digit:
xor edx, edx
div ebx
add dl, '0'
dec esi
mov [esi],dl
test eax, eax
jnz .next_digit
mov eax, esi
ret
This prints random chars when I'm printing the array. Can you tell me where I'm wrong?