home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / sys / atari / st / 21195 < prev    next >
Encoding:
Text File  |  1993-01-28  |  1.3 KB  |  49 lines

  1. Newsgroups: comp.sys.atari.st
  2. Path: sparky!uunet!inmos!fulcrum!bham!warwick!dcs.warwick.ac.uk!leo
  3. From: leo@dcs.warwick.ac.uk (Leo Hendry)
  4. Subject: Re: Assembler routine that generates random numbers?
  5. Message-ID: <1993Jan28.145938.711@dcs.warwick.ac.uk>
  6. Sender: news@dcs.warwick.ac.uk (Network News)
  7. Nntp-Posting-Host: stone
  8. Organization: Department of Computer Science, Warwick University, England
  9. References: <1993Jan20.203516.18565@prime.mdata.fi> <C1EtLI.HDI@cck.coventry.ac.uk> <1993Jan28.120214.19307@cs.hw.ac.uk>
  10. Date: Thu, 28 Jan 1993 14:59:38 GMT
  11. Lines: 36
  12.  
  13. In article <1993Jan28.120214.19307@cs.hw.ac.uk> sbrown@cee.hw.ac.uk (Stuart Brown) writes:
  14. >
  15. >random:
  16. >  move.w seed,d0
  17. >  mulu #109,d0
  18. >  add.l #853,d0
  19. >  divu #4096,d0   } EEK!
  20. >  swap d0         } OUCH!
  21. >  move.w d0,seed
  22. >  rts
  23. >seed
  24. >  dc.w 0
  25. >
  26.  
  27. Your not seriously suggesting using DIVU to get the modulo 4096 are you?
  28. What is the matter with good old AND #4095,D0?  Why ADD.L?
  29. The fastest way (probably) is
  30.  
  31. seed EQU 0
  32.   LEA base(PC),A6
  33. .
  34. .
  35. random:
  36.   MOVE.W seed(A6),D0
  37.   MULU.W #109,D0
  38.   ADD.W  #853,D0
  39.   AND.W  #4095,D0
  40.   MOVE.W D0,seed(A6)
  41.   RTS
  42. base:
  43.   DC.W 0
  44.  
  45. Use the 128x-16x-4x+x expansion for 109x may or may not be faster still,
  46. but probably not worth while because you would change another register.
  47.  
  48. - Leo
  49.