diff options
author | pacien | 2018-04-29 20:22:24 +0200 |
---|---|---|
committer | pacien | 2018-04-29 20:22:24 +0200 |
commit | 80d7f0f204aacefa768d34f6db30108cb430cede (patch) | |
tree | cfccc281c8e50938dd9c3950182d515eb7953dc8 /examples/factorial.eurm | |
parent | 55f5d164762fc37fc53e6e94da2aa92d84e8c145 (diff) | |
download | urm-80d7f0f204aacefa768d34f6db30108cb430cede.tar.gz |
Add factorial example EURM program
Diffstat (limited to 'examples/factorial.eurm')
-rw-r--r-- | examples/factorial.eurm | 23 |
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 @@ | |||
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 | ||