home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 5 / ctrom5b.zip / ctrom5b / PROGRAM / ASM / ALIB30B / RANDOM4.ASM < prev    next >
Assembly Source File  |  1994-11-14  |  2KB  |  92 lines

  1.     page    66,132
  2. ;******************************* RANDOM4.ASM *********************************
  3.  
  4. LIBSEG           segment byte public "LIB"
  5.         assume cs:LIBSEG , ds:nothing
  6.  
  7. ;----------------------------------------------------------------------------
  8. .xlist
  9.     include  mac.inc
  10.     include  common.inc
  11.     extrn    random_seed:far
  12. .list
  13. comment 
  14. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -( RANDOM  )
  15. RANDOM_DWORD1 - generate random dword value
  16. ;
  17. ;  inputs:  none
  18. ;  output:  dx,ax = random value
  19. ;         
  20. * * * * * * * * * * * * * *
  21. 
  22.  
  23. prev_rand    dd    ?        ;previous random, used as seed
  24. rand_delta    dw    ?        ;delta lo-hi randow words
  25. init_flag4    db    0        ;set to 1 if initialized
  26.  
  27. permute1    EQU    0B303h
  28. permute2    EQU    02D8Dh
  29.  
  30. ;------------------------------
  31.     PUBLIC    RANDOM_DWORD1
  32. RANDOM_DWORD1    PROC    NEAR
  33.     cmp    cs:init_flag4,0
  34.     jne    cont4
  35.     call    rw3_init
  36. cont4:    apush    si,di
  37.     xor    di,di
  38.     mov    ax,permute1
  39.     mul    WORD PTR [prev_rand]
  40.     mov    si,ax        
  41.     mov    bx,dx
  42.     add    bx,ax        
  43.     mov    cx,dx
  44.  
  45.     mov    ax,permute2
  46.     mul    WORD PTR [prev_rand+2]
  47.     add    bx,ax            
  48.     adc    cx,dx
  49.     adc    di,0
  50.     add    cx,ax            
  51.     adc    di,dx
  52.  
  53.     mov    ax,permute2-permute1    
  54.     mul    WORD PTR [rand_delta]    
  55.     add    bx,ax            
  56.     adc    cx,dx
  57.     adc    di,0
  58.  
  59.     shl    bx,1
  60.     rcl    cx,1
  61.     rcl    di,1            
  62.     shr    bx,1            
  63.  
  64.     add    si,cx            
  65.     adc    bx,di            
  66.  
  67.     mov    WORD PTR [prev_rand+2],bx        ;save random number
  68.     mov    WORD PTR [prev_rand],si        ;  as seed for next entry
  69.     mov    ax,si                ;pass back result in DX:AX
  70.     mov    dx,bx
  71.     sub    si,bx
  72.     mov    WORD PTR [rand_delta],si
  73.     apop    di,si
  74.     retf
  75. RANDOM_DWORD1    ENDP
  76. ;----------------------------------------
  77. rw3_init    PROC    NEAR
  78. PUBLIC    rw3_init
  79.     call    random_seed
  80.     mov    dx,ax
  81.     rol    dx,1
  82.     mov    WORD PTR [prev_rand],ax
  83.     mov    WORD PTR [prev_rand+2],dx
  84.     sub    ax,dx
  85.     mov    WORD PTR [rand_delta],dx
  86.     mov    cs:init_flag4,1
  87.     ret
  88. rw3_init    ENDP
  89.  
  90. LIBSEG    ENDS
  91. ;;    end
  92.