home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS 1992 September
/
Simtel20_Sept92.cdr
/
msdos
/
progjorn
/
pj_7_6.arc
/
RANDOM.ASM
< prev
next >
Wrap
Assembly Source File
|
1989-08-31
|
1KB
|
59 lines
dosseg
.model small
.stack
NULL segment para public 'BEGDATA' ; force paragraph
NULL ends ; alignment in DGROUP
.data
dgroup_str struc
ran_num dw 0 ; random number seed
ran_mod dw 0FFEFh ; modulus 2^16-17
ran_mul dw 0FFD9h ; multiplier 2^16-39
ran_inc dw 0FFFFh ; increment -1
dgroup_str ends
dgroup_start dgroup_str <> ; allocate space for dgroup structure
.code
extrn exit_program:near,outchr_newline:near,outchr_unsigned:near
;; main
;
main proc
mov ax,@data ; compensate for MS-LINK
mov ss,ax ; bug which fails to set
mov sp,offset stack ; DGROUP relative SS:SP
cld ; "start up" code for this
mov bp,offset dgroup_start ; memory model
mov cx,10 ; display some random numbers
mai1: call random_number
call outchr_unsigned
call outchr_newline
loop mai1
mov ax,ax
jmp exit_program
main endp
;; random number
;
; exit AX random number
;
random_number proc
push dx ; compute random number using
mov ax,ran_num[bp] ; linear congruential method.
mul ran_mul[bp] ; see Knuth: Seminumerical
add ax,ran_inc[bp] ; Algorithms
adc dx,0
div ran_mod[bp]
xchg ax,dx
mov ran_num[bp],ax
pop dx
ret
random_number endp
end main