aboutsummaryrefslogtreecommitdiff
path: root/examples/factorial.eurm
diff options
context:
space:
mode:
authorpacien2018-04-29 20:22:24 +0200
committerpacien2018-04-29 20:22:24 +0200
commit80d7f0f204aacefa768d34f6db30108cb430cede (patch)
treecfccc281c8e50938dd9c3950182d515eb7953dc8 /examples/factorial.eurm
parent55f5d164762fc37fc53e6e94da2aa92d84e8c145 (diff)
downloadurm-80d7f0f204aacefa768d34f6db30108cb430cede.tar.gz
Add factorial example EURM program
Diffstat (limited to 'examples/factorial.eurm')
-rw-r--r--examples/factorial.eurm23
1 files changed, 23 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 @@
1COMMENT compute |R1| ! and place the result in register R1.
2ZERO? 1 R1=0
3GOTO R1>0
4COMMENT R1=0, we are done as 0 ! = 1.
5LABEL R1=0
6INC 1
7GOTO done
8COMMENT R1>0, use n ! = 1 x 2 x ... x n
9LABEL R1>0
10COPY 2 1
11ZERO 1
12INC 1
13ZERO 3
14INC 3
15COMMENT main loop
16LABEL loop
17MULT 1 3
18EQ? 2 3 done
19INC 3
20GOTO loop
21COMMENT that’s all folks.
22LABEL done
23QUIT