After every 5 elements the next element should be printed on the next line. I am not allowed to use a string of empty spaces for the space between the elements. I tried using GoToXy, but I am having trouble. All elements in the first row have 5 spaces between them, starting from the second row all the elements need to be aligned to the one above it.
Desired Output:
94 2 67 57 7
40 58 48 73 94
16 77 88 16
Output from my code: (Everything is printed on the same line with 5 spaces between them.)
94 2 67 57 7 40 58 48 73 94 16 77 88 16
My code is:
INCLUDE Irvine32.inc
.data
count = 14
array WORD count DUP(?)
.code
main PROC
push OFFSET array
push COUNT
call ArrayFill
call DisplayArray
exit
main ENDP
;-----------------------------------------------------------------------------------------
ArrayFill PROC
push ebp
mov ebp,esp
pushad ; save registers
mov esi,[ebp+12] ; offset of array
mov ecx,[ebp+8] ; array size
cmp ecx,0 ; ECX == 0?
je L2 ; yes: skip over loop
L1:
mov eax, 100
call RandomRange ; from the link library
mov [esi],ax
add esi,TYPE WORD
loop L1
L2: popad ; restore registers
pop ebp
ret 8 ; clean up the stack
ArrayFill ENDP
;---------------------------------------------------------------------------------------
DisplayArray PROC
mov eax, 0
mov esi, 0
mov ecx, COUNT
mov dh, 0
call GoToXy
mov dl, 5
L1:
mov ax, array[esi * TYPE array]
call WriteDec
call GoToXy
add dl, 5
inc esi
loop L1
call CrlF
ret
DisplayArray ENDP
END main