.model small .586 .stack 100h .data dtime dw 500 ;; wait time in milliseconds itimelow dd 0 ;; used by delay routine itimehigh dd 0 .code extern Crlf:proc extern Randomize:proc, random_range:proc, Random32:proc ;; write a random digit with specified delay until any ;; character is entered main proc mov ax,@data mov ds,ax call Crlf call Randomize ;; init random num gen lp1: mov eax,10 call Random_range ;; gen random num 0 to 9 add al,30h ;; convert to '0' to '9' mov dl,al mov ah,2 int 21h ;; display with DOS mov cx,dtime ;; get time to wait call mywait ;; check if a key is pressed mov ah,6 mov dl,0ffh int 21h jz lp1 ; Zflag = 1 if no char, so loop Mov ax, 4c00h ;exit Int 21h Main endp CLKFREQ EQU 800 ;; clock frequency in MHZ TICS_MS EQU CLKFREQ*1000 ;; will delay # of milliseconds specified in CX. Register CX destroyed mywait proc push eax push edx mywaitlp2: call timget mov itimelow,eax mov itimehigh,edx mywaitlp1: call timget sub eax,itimelow sbb edx,itimehigh ;; edx:eax has delta time. Compare to TICS_MS sub eax,tics_ms sbb edx,0 jc mywaitlp1 loop mywaitlp2 pop edx pop eax ret mywait endp ;;; procedure that returns the Pentium+ 64 bit timer value ;;; in EDX:EAX timget proc ;;db 0fh,31h rdtsc ;; read timestamp counter ret timget endp end main