aboutsummaryrefslogtreecommitdiff
path: root/examples/factorial.eurm
blob: f22cc190378d5209b7e6feef267d79a81742eefd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
COMMENT compute |R1| ! and place the result in register R1.
ZERO? 1 R1=0
GOTO R1>0
COMMENT R1=0, we are done as 0 ! = 1.
LABEL R1=0
INC 1
GOTO done
COMMENT R1>0, use n ! = 1 x 2 x ... x n
LABEL R1>0
COPY 2 1
ZERO 1
INC 1
ZERO 3
INC 3
COMMENT main loop
LABEL loop
MULT 1 3
EQ? 2 3 done
INC 3
GOTO loop
COMMENT that’s all folks.
LABEL done
QUIT