rand ?

Kosta kosta
Středa Březen 17 11:53:52 CET 2004


Taky jeden generator pseudonahodmych cisel, scucnuto z
http://www.allcode.com/8051/


;11 Nov 99 copied seed from test snippet so it would assemble
;16 May 99 8051 source code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;RNUMB16 is called to generate a 16-bit random number. To prevent the
; same sequence of random numbers from being generated on each call,
; the caller should initialize the 16-bit value, seed, to a different
; value before each series of calls. Input from a real-time clock might
; be a good value for seed as well as a number supplied from reading
; a keyboard.
;
;On return:
; seed has the new number, acc = lsb's of seed, b = msb's of seed,
; All registers have been saved
;
;Call:
;     call  RNUMB16     ;Get random number in seed; b,acc
;
;Notes:
;
; (1)RNUMB16 uses the formula:
;    seed = (seed * 6255h + 3619h)mod 10000h attributed to
;    Peter Grogono, Programming in Pascal, 1984 Addison-Wesley Pub.
; (2)Let seed = s2*2**8 + s1, then
;    seed = (s2*2**8 + s1)*(62h*2**8 + 55h) + 36h*2**8 + 19h
;    = (62h*s2)2**16 + (62h*s1+ 55h*s2 + 36h)2**8 + 55h*s1 + 19h
;    = (62h*s1+ 55h*s2 + 36h)2**8 + 55h*s1 + 19h
;
; Original author: John Veazey, Ridgecrest, CA, 08 May 99
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
dseg
seed: ds 2 ;The random number generated, caller can initializes on
           ; first call
cseg
RNUMB16:
;
;Get the 55h*s1 + 19h + 36h*2**8 terms
;
      mov   b,#55h
      mov   a,seed
      mul   ab
      add   a,#19h      ;c set
      push  acc         ;Save 2**0
      mov   a,b
      addc  a,#36h
      push  acc         ;Save 2**8
;
;Get the 62h*s1*2**8 term, discarding 2**16 terms produced
;
      mov   b,#62h
      mov   a,seed
      mul   ab
      pop   b           ;Get 2**8, discarding 2**16
      add   a,b
      push  acc         ;Save 2**8
;
;Get the 55h*s2*2**8 terms, discarding 2**16 terms produced
;
      mov   b,seed+1
      mov   a,#55h
      mul   ab
      pop   b           ;Get 2**8, discarding 2**16
      add   a,b         ;c set
      mov   b,a         ;Update 2**8
      mov   seed+1,a
      pop   acc         ;Get 2**8
      mov   seed,a
;
;Return to caller with random number in acc and b
;
      ret
;end of RNUMB


Kosta

kosta@iol.cz
-------------------------------------------
             Kosta
             P.O.Box 38
             Posta 41
141 00  Praha 4 - Sporilov
-------------------------------------------
0603 / 33 87 47
-------------------------------------------







Další informace o konferenci Hw-list