I want to store random numbers from 1 to 5 in an array of 100 bytes. My random procedure is working well but it did not show any output when I tried to print my array. This program did not show any output. I have checked my random number procedure and it works fine, but I think there is some issue with storing and printing.
Here is my code:
.model small
.stack 100h
.data
arrayelement db 100 dup('$'); To store array
randomnumber db 0; to store random number
r1 db ?
.code
main proc
mov ax,@data
mov ds,ax
mov cx,100
mov si,offset arrayelement
forr:
call random
mov al,randomnumber
mov [si],al
inc si
loop forr
mov dl,10
mov ah,02h
int 21H
mov dl,13
mov ah,02h
int 21H
mov si,offset arrayelement
mov cx,100
for1:
mov dl,[si]
;add dl,48
mov ah,02
int 21h
inc si
loop for1
mov ah,4ch
int 21h
main endp
;Random procedure to print randomnumber between 1 to 5
random proc
mov ax,0
mov bx,0
mov cx,0
mov dx,0
;Loop to slow down time so it print different random number on each call
mov cx,500
l11:
push cx
mov cx,500
l222:
Loop l222
pop cx
Loop l11
MOV AH, 00h ; interrupts to get system time
INT 1AH ; CX:DX now hold number of clock ticks since midnight
mov ax, dx
xor dx, dx
mov cx, 5 ;Ending
div cx ; here dx contains the remainder of the division - from 1-5
add dl, 1 ; start--to ascii from '1' to '5'
mov randomnumber,dl
ret
random endp
end main