Next is a little program to display an array of numbers (EMU8086 Intel sytanx) :
.stack 100h
.data
numbers dw 130,50,260,570,180,190,100,20,66,140,860,470,190,20,220,250,170,30,300,0
str db 6 dup('$') ;STRING TO STORE NUMBER CONVERTED INTO STRING.
crlf db 13,10,'$'
.code
;INITIALIZE DATA SEGMENT.
mov ax, @data
mov ds, ax
mov di, offset numbers ;DI POINTS TO THE NUMBERS.
while:
;CONVERT CURRENT NUMBER TO STRING.
call dollars ;FILL "STR" WITH '$'. NECESSARY TO DISPLAY IT.
mov ax, [ di ] ;GET CURRENT NUMBER.
call number2string ;CONVERT AX TO STRING. RESULT IN "STR".
;DISPLAY NUMBER CONVERTED.
mov ah, 9
mov dx, offset str
int 21h
;DISPLAY LINE BREAK.
mov ah, 9
mov dx, offset crlf
int 21h
;NEXT NUMBER TO PROCESS.
add di, 2 ;2 BYTES FORWARD BECAUSE NUMBERS ARE "DW".
;CHECK IF PROCESS IS OVER.
mov ax, [ di ]
cmp ax, 0
jne while ;IF AX!=0 JMP WHILE.
;FINISH PROGRAM.
mov ax, 4c00h
int 21h
;------------------------------------------
;NUMBER TO CONVERT MUST ENTER IN AX.
;ALGORITHM : EXTRACT DIGITS ONE BY ONE, STORE
;THEM IN STACK, THEN EXTRACT THEM IN REVERSE
;ORDER TO CONSTRUCT STRING.
proc number2string
mov bx, 10 ;DIGITS ARE EXTRACTED DIVIDING BY 10.
mov cx, 0 ;COUNTER FOR EXTRACTED DIGITS.
cycle1:
mov dx, 0 ;NECESSARY TO DIVIDE BY BX.
div bx ;DX:AX / 10 = AX:QUOTIENT DX:REMAINDER.
push dx ;PRESERVE DIGIT EXTRACTED FOR LATER.
inc cx ;INCREASE COUNTER FOR EVERY DIGIT EXTRACTED.
cmp ax, 0 ;IF NUMBER IS
jne cycle1 ;NOT ZERO, LOOP.
;NOW RETRIEVE PUSHED DIGITS.
mov si, offset str
cycle2:
pop dx
add dl, 48 ;CONVERT DIGIT TO CHARACTER.
mov [ si ], dl
inc si
loop cycle2
ret
endp
;------------------------------------------
;FILLS VARIABLE STR WITH '$'.
;USED BEFORE CONVERT NUMBERS TO STRING, BECAUSE
;THESE STRINGS WILL BE DISPLAYED.
proc dollars
mov si, offset str
mov cx, 6
six_dollars:
mov al, '$'
mov [ si ], al
inc si
loop six_dollars
ret
endp
Now previous code with your random proc, it first fills the array with 40 random numbers (20 pairs X,Y), and displays them :
.stack 100h
.data
gen_row_star db ?
gen_col_star db ?
array db 40 dup(?) ;STORES 20 PAIRS OF RANDOM NUMBERS.
str db 6 dup('$') ;STRING TO STORE NUMBER CONVERTED INTO STRING.
comma db ',$'
crlf db 13,10,'$'
.code
;INITIALIZE DATA SEGMENT.
mov ax, @data
mov ds, ax
;FILL ARRAY WITH RANDOM NUMBERS.
mov di, offset array
mov bp, 20 ;GENERATE 20 PAIRS OF RANDOM NUMBERS.
fill_array:
call random_coor_star ;NUMBERS RETURN IN gen_row_star AND gen_col_star.
mov al, gen_col_star
mov [ di ], al ;MOVE FIRST NUMBER OF PAIR TO ARRAY (X COORDINATE).
inc di
mov al, gen_row_star
mov [ di ], al ;MOVE SECOND NUMBER OF PAIR TO ARRAY (Y COORDINATE).
inc di
dec bp
jnz fill_array
;DISPLAY ARRAY.
mov di, offset array ;DI POINTS TO THE ARRAY.
mov bp, 20 ;DISPLAY 20 PAIRS OF RANDOM NUMBERS.
while:
;- - - X COORDINATE.
;CONVERT CURRENT NUMBER TO STRING.
call dollars ;FILL "STR" WITH '$'. NECESSARY TO DISPLAY IT.
mov al, [ di ] ;GET CURRENT NUMBER.
mov ah, 0 ;CLEAR AH TO USE AX.
call number2string ;CONVERT AX TO STRING. RESULT IN "STR".
;DISPLAY NUMBER CONVERTED.
mov ah, 9
mov dx, offset str
int 21h
;DISPLAY COMMA.
mov ah, 9
mov dx, offset comma
int 21h
;- - - Y COORDINATE.
inc di ;NEXT NUMBER OF CURRENT PAIR.
;CONVERT CURRENT NUMBER TO STRING.
call dollars ;FILL "STR" WITH '$'. NECESSARY TO DISPLAY IT.
mov al, [ di ] ;GET CURRENT NUMBER.
mov ah, 0 ;CLEAR AH TO USE AX.
call number2string ;CONVERT AX TO STRING. RESULT IN "STR".
;DISPLAY NUMBER CONVERTED.
mov ah, 9
mov dx, offset str
int 21h
;DISPLAY LINE BREAK.
mov ah, 9
mov dx, offset crlf
int 21h
;CHECK IF PROCESS IS OVER.
inc di ;NEXT NUMBER (NEXT PAIR OF COORDINATES).
dec bp
jnz while
;FINISH PROGRAM.
mov ax, 4c00h
int 21h
;------------------------------------------
;DR.DOOM'S RANDOM PROC.
random_coor_star proc
mov ah, 00h
int 1ah
mov ah, 00h
int 1ah
mov ax,dx
xor dx,dx
mov cx,10
div cx
add dl, 5
mov al,dl
mov gen_row_star,al
mov ah, 00h
int 1ah
mov ah, 00h
int 1ah
mov ax,dx
xor dx,dx
mov cx,50
div cx
add dl,5
mov al,dl
mov gen_col_star,al
ret
random_coor_star endp
;------------------------------------------
;NUMBER TO CONVERT MUST ENTER IN AX.
;ALGORITHM : EXTRACT DIGITS ONE BY ONE, STORE
;THEM IN STACK, THEN EXTRACT THEM IN REVERSE
;ORDER TO CONSTRUCT STRING.
proc number2string
mov bx, 10 ;DIGITS ARE EXTRACTED DIVIDING BY 10.
mov cx, 0 ;COUNTER FOR EXTRACTED DIGITS.
cycle1:
mov dx, 0 ;NECESSARY TO DIVIDE BY BX.
div bx ;DX:AX / 10 = AX:QUOTIENT DX:REMAINDER.
push dx ;PRESERVE DIGIT EXTRACTED FOR LATER.
inc cx ;INCREASE COUNTER FOR EVERY DIGIT EXTRACTED.
cmp ax, 0 ;IF NUMBER IS
jne cycle1 ;NOT ZERO, LOOP.
;NOW RETRIEVE PUSHED DIGITS.
mov si, offset str
cycle2:
pop dx
add dl, 48 ;CONVERT DIGIT TO CHARACTER.
mov [ si ], dl
inc si
loop cycle2
ret
endp
;------------------------------------------
;FILLS VARIABLE STR WITH '$'.
;USED BEFORE CONVERT NUMBERS TO STRING, BECAUSE
;THESE STRINGS WILL BE DISPLAYED.
proc dollars
mov si, offset str
mov cx, 6
six_dollars:
mov al, '$'
mov [ si ], al
inc si
loop six_dollars
ret
endp