-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfibsub.mms
More file actions
44 lines (40 loc) · 759 Bytes
/
fibsub.mms
File metadata and controls
44 lines (40 loc) · 759 Bytes
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
* Fibonacci subroutines (exercise 1.4.1--13)
LOC #100
Fib CMP $1,$0,2
PBN $1,1F
GET $1,rJ
SUB $3,$0,1
PUSHJ $2,Fib $2=F_{n-1}
SUB $4,$0,2
PUSHJ $3,Fib $3=F_{n-2}
ADDU $0,$2,$3
PUT rJ,$1
1H POP 1,0
Fib1 CMP $1,$0,2
BN $1,1F
SUB $2,$0,1
SET $0,1
SET $1,0
2H ADDU $0,$0,$1 repeated n-1 times
SUBU $1,$0,$1
SUB $2,$2,1
PBNZ $2,2B
1H POP 1,0
Fib2 CMP $1,$0,1
BNP $1,1F
SUB $2,$0,1
SET $0,0
2H ADDU $0,$0,$1
ADDU $1,$0,$1
SUB $2,$2,2
PBP $2,2B
CSZ $0,$2,$1
1H POP 1,0
Main SET $1,5
PUSHJ $0,Fib
SET $1,5
PUSHJ $0,Fib1
SET $1,5
PUSHJ $0,Fib2
SET $1,6
PUSHJ $0,Fib2