🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.atari.st
Article #23556

Re: Assembler routine that generates random numbers?

#23556
From: Leo Hendry
Date: Thu, 28 Jan 1993 14:59
36 lines
1337 bytes
In article <1993Jan28.120214.19307@cs.hw.ac.uk> sbrown@cee.hw.ac.uk (Stuart Brown) writes:
>
>random:
>  move.w seed,d0
>  mulu #109,d0
>  add.l #853,d0
>  divu #4096,d0   } EEK!
>  swap d0         } OUCH!
>  move.w d0,seed
>  rts
>seed
>  dc.w 0
>

Your not seriously suggesting using DIVU to get the modulo 4096 are you?
What is the matter with good old AND #4095,D0?  Why ADD.L?
The fastest way (probably) is

seed EQU 0
  LEA base(PC),A6
.
.
random:
  MOVE.W seed(A6),D0
  MULU.W #109,D0
  ADD.W  #853,D0
  AND.W  #4095,D0
  MOVE.W D0,seed(A6)
  RTS
base:
  DC.W 0

Use the 128x-16x-4x+x expansion for 109x may or may not be faster still,
but probably not worth while because you would change another register.

- Leo
Technical Details
Message-ID: <1993Jan28.145938.711@dcs.warwick.ac.uk>
Path: arc1-ca.pugleaf.net!sparky!uunet!inmos!fulcrum!bham!warwick!dcs.warwick.ac.uk!leo
References: <1993Jan20.203516.18565@prime.mdata.fi> <C1EtLI.HDI@cck.coventry.ac.uk> <1993Jan28.120214.19307@cs.hw.ac.uk>

Show Full Headers
Complete Article Headers
Newsgroups: comp.sys.atari.st
Path: arc1-ca.pugleaf.net!sparky!uunet!inmos!fulcrum!bham!warwick!dcs.warwick.ac.uk!leo
From: leo@dcs.warwick.ac.uk (Leo Hendry)
Subject: Re: Assembler routine that generates random numbers?
Message-ID: <1993Jan28.145938.711@dcs.warwick.ac.uk>
Sender: news@dcs.warwick.ac.uk (Network News)
Nntp-Posting-Host: stone
Organization: Department of Computer Science, Warwick University, England
References: <1993Jan20.203516.18565@prime.mdata.fi> <C1EtLI.HDI@cck.coventry.ac.uk> <1993Jan28.120214.19307@cs.hw.ac.uk>
Date: Thu, 28 Jan 1993 14:59:38 GMT
Lines: 36