home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 5 / ctrom5b.zip / ctrom5b / PROGRAM / ASM / ALIB30B / RANDOM9.ASM < prev    next >
Assembly Source File  |  1994-12-05  |  1KB  |  49 lines

  1.     page    66,132
  2. ;******************************* RANDOM9.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. .list
  12.  
  13. comment 
  14. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -( RANDOM  )
  15. SCALE_WORD - scale a word value to be within specified range
  16. ;  inputs:  bx = low value of range
  17. ;           bp = high value of range
  18. ;           ax = number to scale
  19. ;  output:  ax = scaled number
  20. ;
  21. ;  note:  The number is scaled using the formula
  22. ;
  23. ;          input value              x
  24. ;          ----------- =  -----------------------
  25. ;           0ffffh        (high range - low range)
  26. ;
  27. ;           scaled number = x + low range
  28. ;  
  29. * * * * * * * * * * * * * *
  30. 
  31.  
  32.     public    SCALE_WORD
  33. SCALE_WORD    proc    far
  34.     apush    cx,dx
  35.     mov    cx,bp
  36.     sub    cx,bx        ;compute range delta
  37.     mul    cx        ;(input value) * (delta)
  38.     mov    cx,-1
  39.     cmp    dx,cx        ;verify divide will work
  40.     jae    abort        ;jmp if divide will not work
  41.     div    cx        ;(input value) * (delta) / ffffh
  42.     add    ax,bx        ;result + low range = scaled number
  43. abort:    apop    dx,cx
  44.     retf    
  45. SCALE_WORD    endp
  46.  
  47. LIBSEG    ENDS
  48. ;;    end
  49.