-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathControl.asm
50 lines (46 loc) · 1.1 KB
/
Control.asm
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
; main.s
; Runs on any Cortex M processor
; A very simple first project implementing a random number generator
; Daniel Valvano
; May 12, 2015
.thumb
.data
.align 2
M .space 4
n .space 4
.text
.align 2
.global main
main: .asmfunc
MOV R0,#1 ; Initial seed
BL Seed ; M=1
loop BL Rand
LDR R1,nAddr
STR R0,[R1]
B loop
.endasmfunc
;------------Random------------
; Return R0= random number
; Linear congruential generator
; from Numerical Recipes by Press et al.
Seed: .asmfunc
LDR R1,MAddr ; R1=&M
STR R0,[R1] ; set M
BX LR
.endasmfunc
Rand: .asmfunc
LDR R2,MAddr ; R2=&M, address of M
LDR R0,[R2] ; R0=M, value of M
LDR R1,Slope
MUL R0,R0,R1 ; R0 = 1664525*M
LDR R1,Offst
ADD R0,R0,R1 ; 1664525*M+1013904223
STR R0,[R2] ; store M
LSR R0,#24 ; 0 to 255
BX LR
.endasmfunc
MAddr .field M,32
Slope .field 1664525,32
Offst .field 1013904223,32
nAddr .field n,32
.end