aboutsummaryrefslogtreecommitdiff
path: root/examples/factorial.eurm
diff options
context:
space:
mode:
Diffstat (limited to 'examples/factorial.eurm')
-rw-r--r--examples/factorial.eurm12
1 files changed, 8 insertions, 4 deletions
diff --git a/examples/factorial.eurm b/examples/factorial.eurm
index f22cc19..b2b2566 100644
--- a/examples/factorial.eurm
+++ b/examples/factorial.eurm
@@ -1,23 +1,27 @@
1COMMENT compute |R1| ! and place the result in register R1. 1COMMENT Compute R1! and place the result in R1
2
2ZERO? 1 R1=0 3ZERO? 1 R1=0
3GOTO R1>0 4GOTO R1>0
4COMMENT R1=0, we are done as 0 ! = 1. 5
6COMMENT R1 holds 0
5LABEL R1=0 7LABEL R1=0
6INC 1 8INC 1
7GOTO done 9GOTO done
8COMMENT R1>0, use n ! = 1 x 2 x ... x n 10
11COMMENT R1 holds a positive integer
9LABEL R1>0 12LABEL R1>0
10COPY 2 1 13COPY 2 1
11ZERO 1 14ZERO 1
12INC 1 15INC 1
13ZERO 3 16ZERO 3
14INC 3 17INC 3
18
15COMMENT main loop 19COMMENT main loop
16LABEL loop 20LABEL loop
17MULT 1 3 21MULT 1 3
18EQ? 2 3 done 22EQ? 2 3 done
19INC 3 23INC 3
20GOTO loop 24GOTO loop
21COMMENT that’s all folks. 25
22LABEL done 26LABEL done
23QUIT 27QUIT