diff options
Diffstat (limited to 'examples/factorial.eurm')
-rw-r--r-- | examples/factorial.eurm | 12 |
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 @@ | |||
1 | COMMENT compute |R1| ! and place the result in register R1. | 1 | COMMENT Compute R1! and place the result in R1 |
2 | |||
2 | ZERO? 1 R1=0 | 3 | ZERO? 1 R1=0 |
3 | GOTO R1>0 | 4 | GOTO R1>0 |
4 | COMMENT R1=0, we are done as 0 ! = 1. | 5 | |
6 | COMMENT R1 holds 0 | ||
5 | LABEL R1=0 | 7 | LABEL R1=0 |
6 | INC 1 | 8 | INC 1 |
7 | GOTO done | 9 | GOTO done |
8 | COMMENT R1>0, use n ! = 1 x 2 x ... x n | 10 | |
11 | COMMENT R1 holds a positive integer | ||
9 | LABEL R1>0 | 12 | LABEL R1>0 |
10 | COPY 2 1 | 13 | COPY 2 1 |
11 | ZERO 1 | 14 | ZERO 1 |
12 | INC 1 | 15 | INC 1 |
13 | ZERO 3 | 16 | ZERO 3 |
14 | INC 3 | 17 | INC 3 |
18 | |||
15 | COMMENT main loop | 19 | COMMENT main loop |
16 | LABEL loop | 20 | LABEL loop |
17 | MULT 1 3 | 21 | MULT 1 3 |
18 | EQ? 2 3 done | 22 | EQ? 2 3 done |
19 | INC 3 | 23 | INC 3 |
20 | GOTO loop | 24 | GOTO loop |
21 | COMMENT that’s all folks. | 25 | |
22 | LABEL done | 26 | LABEL done |
23 | QUIT | 27 | QUIT |