From 80d7f0f204aacefa768d34f6db30108cb430cede Mon Sep 17 00:00:00 2001 From: pacien Date: Sun, 29 Apr 2018 20:22:24 +0200 Subject: Add factorial example EURM program --- examples/factorial.eurm | 23 +++++++++++++++++++++++ examples/factorial.reg | 1 + 2 files changed, 24 insertions(+) create mode 100644 examples/factorial.eurm create mode 100644 examples/factorial.reg (limited to 'examples') 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 @@ +COMMENT compute |R1| ! and place the result in register R1. +ZERO? 1 R1=0 +GOTO R1>0 +COMMENT R1=0, we are done as 0 ! = 1. +LABEL R1=0 +INC 1 +GOTO done +COMMENT R1>0, use n ! = 1 x 2 x ... x n +LABEL R1>0 +COPY 2 1 +ZERO 1 +INC 1 +ZERO 3 +INC 3 +COMMENT main loop +LABEL loop +MULT 1 3 +EQ? 2 3 done +INC 3 +GOTO loop +COMMENT that’s all folks. +LABEL done +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 -- cgit v1.2.3