home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff218.lzh / Worm / rnd.asm < prev    next >
Assembly Source File  |  1989-06-04  |  747b  |  43 lines

  1. *\
  2. *  :ts=8
  3. * Yet Another random number generator.  By Leo Schwab.
  4. * Based on an idea posted on the USENET (Thanks, Sam Dicker!)
  5. * For the Manx assembler.
  6. *
  7. * Calling convention:
  8. *  short rnd (range);
  9. *  short range;
  10. *
  11. * 8606.30
  12. */
  13.  
  14.         XDEF    _rnd
  15.         SECTION    __RNDCODE,CODE
  16.  
  17. _rnd        lea    rndseed,a0    Get address of seed
  18.         move.l    4(sp),d1    Get range argument
  19.         tst.w    d1
  20.         ble.s    setseed        Go reset seed
  21.  
  22.  
  23.         move.l    (a0),d0        Get seed
  24.         ADD.L   D0,D0
  25.         BHI.S   over
  26.         EORI.L  #$1D872B41,D0
  27. over
  28.         move.l    d0,(a0)        Save new seed
  29.         andi.l    #$ffff,d0    Coerce into word
  30.         divu    d1,d0        Divide by range
  31.         swap    d0         and get remainder (modulus)
  32.         rts
  33.  
  34. setseed        neg.w    d1        Probably don't need this
  35.         move.l    d1,(a0)
  36.         rts
  37.  
  38.         SECTION    __RNDDATA,DATA
  39. rndseed        dc.l    0
  40.         END
  41.  
  42.         
  43.