File: random.s

package info (click to toggle)
tkisem 4.5.12-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 964 kB
  • ctags: 1,372
  • sloc: cpp: 4,844; tcl: 3,047; asm: 1,991; makefile: 335; ansic: 269; sh: 155
file content (68 lines) | stat: -rw-r--r-- 1,228 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
!
!  $Id: random.s 1.1 Fri, 25 Oct 1996 18:04:04 -0600 maccabe $
!
!  a 16-bit random number generator for tkisem
!
!  
! From: tshiono@cv.sony.co.jp (Toru Shiono)
!    (posted to comp.lang.tcl -- you get numbers where you can find them)
!
!set _Randseed 1
!
!proc rand {} {
!    global _Randseed
!    set _Randseed [expr $_Randseed * 1103515245 + 12345]
!    return [expr ($_Randseed >> 16) & 32767]
!}
!
!proc srand {seed} {
!    global _Randseed
!    set _Randseed $seed
!}

	! defined symbols
	mpy = 1103515245
	add = 12345

	! exported names
	.global srand, rand
	
	! global (private) variables
	.data
	.align	4
	.word	0
seed:	.word	1

	.text
	.align	8
	
	!---------------------------------------------------------------------
	! srand -- seed the random number generator
	!  -- written as an optimized leaf routine
srand:
	sethi	%hi(seed), %o1

	retl
	st	%o0, [%o1+%lo(seed)]


	.text
	.align	8
	
	!---------------------------------------------------------------------
	! rand -- return a random number
	!  -- written as an optimized leaf routine
rand:
	sethi	%hi(seed), %o1
	ld	[%o1+%lo(seed)], %o0
	set	mpy, %o2
	umul	%o0, %o2, %o0
	set	add, %o2
	add	%o0, %o2, %o0
	st	%o0, [%o1+%lo(seed)]
	retl
	srl	%o0, 16, %o0