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