From 37716a32c9aadcca83746bf96bf32b552fa55847 Mon Sep 17 00:00:00 2001 From: pacien Date: Mon, 30 Apr 2018 23:21:17 +0200 Subject: Add examples from S.V website --- examples/add.eurm | 3 +++ examples/add.urm | 16 +++++----------- examples/even.eurm | 25 +++++++++++++++++++++++++ examples/even.reg | 1 + examples/even.urm | 11 +++++++++++ examples/factorial.eurm | 12 ++++++++---- examples/factorial.urm | 30 ++++++++++++++++++++++++++++++ examples/sum-first-integers.eurm | 16 ++++++++++++++++ examples/sum-first-integers.reg | 1 + examples/sum-first-integers.urm | 12 ++++++++++++ examples/sum-first-odd-integers.eurm | 20 ++++++++++++++++++++ examples/sum-first-odd-integers.reg | 1 + examples/sum-first-odd-integers.urm | 21 +++++++++++++++++++++ 13 files changed, 154 insertions(+), 15 deletions(-) create mode 100644 examples/add.eurm create mode 100644 examples/even.eurm create mode 100644 examples/even.reg create mode 100644 examples/even.urm create mode 100644 examples/factorial.urm create mode 100644 examples/sum-first-integers.eurm create mode 100644 examples/sum-first-integers.reg create mode 100644 examples/sum-first-integers.urm create mode 100644 examples/sum-first-odd-integers.eurm create mode 100644 examples/sum-first-odd-integers.reg create mode 100644 examples/sum-first-odd-integers.urm (limited to 'examples') diff --git a/examples/add.eurm b/examples/add.eurm new file mode 100644 index 0000000..7691a3f --- /dev/null +++ b/examples/add.eurm @@ -0,0 +1,3 @@ +COMMENT Add the content of registers 1 and 2. + +ADD 1 2 diff --git a/examples/add.urm b/examples/add.urm index d11eff7..ea8a321 100644 --- a/examples/add.urm +++ b/examples/add.urm @@ -1,11 +1,5 @@ -ZERO 0 -ZERO 3 -JUMP 1 3 6 -SUCC 0 -SUCC 3 -JUMP 3 3 2 -ZERO 3 -JUMP 2 3 11 -SUCC 0 -SUCC 3 -JUMP 3 3 7 +Zero 3 +Jump 2 3 5 +Succ 1 +Succ 3 +Jump 1 1 1 diff --git a/examples/even.eurm b/examples/even.eurm new file mode 100644 index 0000000..f07ad37 --- /dev/null +++ b/examples/even.eurm @@ -0,0 +1,25 @@ +COMMENT Decide wether the content of Register 1 is even. +COMMENT The output is 0 if it is even and 1 otherwise + +COMMENT initialization +ZERO 2 + +COMMENT main loop +LABEL loop +COMMENT invariant: R2 is even +EQ? 1 2 even +INC 2 +COMMENT invariant: R2 is odd +EQ? 1 2 odd +INC 2 +GOTO loop + +COMMENT R1 holds an even number +LABEL even +ZERO 1 +QUIT + +COMMENT R1 holds an odd number +LABEL odd +ZERO 1 +INC 1 diff --git a/examples/even.reg b/examples/even.reg new file mode 100644 index 0000000..281994b --- /dev/null +++ b/examples/even.reg @@ -0,0 +1 @@ +1 51 diff --git a/examples/even.urm b/examples/even.urm new file mode 100644 index 0000000..9f2e17c --- /dev/null +++ b/examples/even.urm @@ -0,0 +1,11 @@ +ZERO 2 +JUMP 1 2 7 +SUCC 2 +JUMP 1 2 9 +SUCC 2 +ZERO 3 +JUMP 3 3 1 +ZERO 1 +JUMP 1 1 11 +ZERO 1 +SUCC 1 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 @@ -COMMENT compute |R1| ! and place the result in register R1. +COMMENT Compute R1! and place the result in R1 + ZERO? 1 R1=0 GOTO R1>0 -COMMENT R1=0, we are done as 0 ! = 1. + +COMMENT R1 holds 0 LABEL R1=0 INC 1 GOTO done -COMMENT R1>0, use n ! = 1 x 2 x ... x n + +COMMENT R1 holds a positive integer 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.urm b/examples/factorial.urm new file mode 100644 index 0000000..04d6e1d --- /dev/null +++ b/examples/factorial.urm @@ -0,0 +1,30 @@ +ZERO 4 +JUMP 1 4 4 +ZERO 8 +JUMP 8 8 7 +Succ 1 +ZERO 9 +JUMP 9 9 29 +COPY 2 1 +ZERO 1 +Succ 1 +ZERO 3 +Succ 3 +COPY 6 1 +ZERO 1 +ZERO 5 +JUMP 3 5 25 +ZERO 7 +JUMP 6 7 22 +Succ 1 +Succ 7 +ZERO 10 +JUMP 10 10 17 +Succ 5 +ZERO 11 +JUMP 11 11 15 +JUMP 2 3 29 +Succ 3 +ZERO 12 +JUMP 12 12 12 +JUMP 1 1 30 diff --git a/examples/sum-first-integers.eurm b/examples/sum-first-integers.eurm new file mode 100644 index 0000000..0bfae93 --- /dev/null +++ b/examples/sum-first-integers.eurm @@ -0,0 +1,16 @@ +COMMENT Put in Register 1 the sum 1 + 2 + ... + n, +COMMENT where n is the initial value of Register 1. + +COMMENT Initialization +COPY 2 1 +ZERO 3 + +COMMENT Main loop +LABEL loop +EQ? 2 3 done +ADD 1 3 +INC 3 +GOTO loop + +COMMENT That's all folks ! +LABEL done diff --git a/examples/sum-first-integers.reg b/examples/sum-first-integers.reg new file mode 100644 index 0000000..281994b --- /dev/null +++ b/examples/sum-first-integers.reg @@ -0,0 +1 @@ +1 51 diff --git a/examples/sum-first-integers.urm b/examples/sum-first-integers.urm new file mode 100644 index 0000000..363dbdd --- /dev/null +++ b/examples/sum-first-integers.urm @@ -0,0 +1,12 @@ +COPY 2 1 +ZERO 3 +JUMP 2 3 12 +ZERO 4 +JUMP 3 4 9 +SUCC 1 +SUCC 4 +ZERO 5 +JUMP 5 5 4 +SUCC 3 +ZERO 6 +JUMP 6 6 2 diff --git a/examples/sum-first-odd-integers.eurm b/examples/sum-first-odd-integers.eurm new file mode 100644 index 0000000..f3e6ddb --- /dev/null +++ b/examples/sum-first-odd-integers.eurm @@ -0,0 +1,20 @@ +COMMENT Compute sum 1 + 3 + 5 + ... + n, where n is the greatest +COMMENT integer less or equal to the initial value of Register 1. + +COMMENT Initialization +ZERO 2 +INC 2 +ZERO 3 + +COMMENT Main loop +LABEL loop +EQ? 2 1 continue +GEQ? 2 1 done +LABEL continue +ADD 3 2 +INC 2 +INC 2 +GOTO loop + +LABEL done +COPY 1 3 diff --git a/examples/sum-first-odd-integers.reg b/examples/sum-first-odd-integers.reg new file mode 100644 index 0000000..281994b --- /dev/null +++ b/examples/sum-first-odd-integers.reg @@ -0,0 +1 @@ +1 51 diff --git a/examples/sum-first-odd-integers.urm b/examples/sum-first-odd-integers.urm new file mode 100644 index 0000000..e476a5a --- /dev/null +++ b/examples/sum-first-odd-integers.urm @@ -0,0 +1,21 @@ +ZERO 2 +SUCC 2 +ZERO 3 +JUMP 2 1 10 +ZERO 4 +JUMP 2 4 10 +JUMP 1 4 20 +SUCC 4 +ZERO 6 +JUMP 6 6 5 +ZERO 5 +JUMP 2 5 16 +SUCC 3 +SUCC 5 +ZERO 7 +JUMP 7 7 11 +SUCC 2 +SUCC 2 +ZERO 8 +JUMP 8 8 3 +COPY 1 3 -- cgit v1.2.3