aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/add.eurm3
-rw-r--r--examples/add.urm16
-rw-r--r--examples/even.eurm25
-rw-r--r--examples/even.reg1
-rw-r--r--examples/even.urm11
-rw-r--r--examples/factorial.eurm12
-rw-r--r--examples/factorial.urm30
-rw-r--r--examples/sum-first-integers.eurm16
-rw-r--r--examples/sum-first-integers.reg1
-rw-r--r--examples/sum-first-integers.urm12
-rw-r--r--examples/sum-first-odd-integers.eurm20
-rw-r--r--examples/sum-first-odd-integers.reg1
-rw-r--r--examples/sum-first-odd-integers.urm21
13 files changed, 154 insertions, 15 deletions
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 @@
1COMMENT Add the content of registers 1 and 2.
2
3ADD 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 @@
1ZERO 0 1Zero 3
2ZERO 3 2Jump 2 3 5
3JUMP 1 3 6 3Succ 1
4SUCC 0 4Succ 3
5SUCC 3 5Jump 1 1 1
6JUMP 3 3 2
7ZERO 3
8JUMP 2 3 11
9SUCC 0
10SUCC 3
11JUMP 3 3 7
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 @@
1COMMENT Decide wether the content of Register 1 is even.
2COMMENT The output is 0 if it is even and 1 otherwise
3
4COMMENT initialization
5ZERO 2
6
7COMMENT main loop
8LABEL loop
9COMMENT invariant: R2 is even
10EQ? 1 2 even
11INC 2
12COMMENT invariant: R2 is odd
13EQ? 1 2 odd
14INC 2
15GOTO loop
16
17COMMENT R1 holds an even number
18LABEL even
19ZERO 1
20QUIT
21
22COMMENT R1 holds an odd number
23LABEL odd
24ZERO 1
25INC 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 @@
1ZERO 2
2JUMP 1 2 7
3SUCC 2
4JUMP 1 2 9
5SUCC 2
6ZERO 3
7JUMP 3 3 1
8ZERO 1
9JUMP 1 1 11
10ZERO 1
11SUCC 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 @@
1COMMENT compute |R1| ! and place the result in register R1. 1COMMENT Compute R1! and place the result in R1
2
2ZERO? 1 R1=0 3ZERO? 1 R1=0
3GOTO R1>0 4GOTO R1>0
4COMMENT R1=0, we are done as 0 ! = 1. 5
6COMMENT R1 holds 0
5LABEL R1=0 7LABEL R1=0
6INC 1 8INC 1
7GOTO done 9GOTO done
8COMMENT R1>0, use n ! = 1 x 2 x ... x n 10
11COMMENT R1 holds a positive integer
9LABEL R1>0 12LABEL R1>0
10COPY 2 1 13COPY 2 1
11ZERO 1 14ZERO 1
12INC 1 15INC 1
13ZERO 3 16ZERO 3
14INC 3 17INC 3
18
15COMMENT main loop 19COMMENT main loop
16LABEL loop 20LABEL loop
17MULT 1 3 21MULT 1 3
18EQ? 2 3 done 22EQ? 2 3 done
19INC 3 23INC 3
20GOTO loop 24GOTO loop
21COMMENT that’s all folks. 25
22LABEL done 26LABEL done
23QUIT 27QUIT
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 @@
1ZERO 4
2JUMP 1 4 4
3ZERO 8
4JUMP 8 8 7
5Succ 1
6ZERO 9
7JUMP 9 9 29
8COPY 2 1
9ZERO 1
10Succ 1
11ZERO 3
12Succ 3
13COPY 6 1
14ZERO 1
15ZERO 5
16JUMP 3 5 25
17ZERO 7
18JUMP 6 7 22
19Succ 1
20Succ 7
21ZERO 10
22JUMP 10 10 17
23Succ 5
24ZERO 11
25JUMP 11 11 15
26JUMP 2 3 29
27Succ 3
28ZERO 12
29JUMP 12 12 12
30JUMP 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 @@
1COMMENT Put in Register 1 the sum 1 + 2 + ... + n,
2COMMENT where n is the initial value of Register 1.
3
4COMMENT Initialization
5COPY 2 1
6ZERO 3
7
8COMMENT Main loop
9LABEL loop
10EQ? 2 3 done
11ADD 1 3
12INC 3
13GOTO loop
14
15COMMENT That's all folks !
16LABEL 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 @@
1COPY 2 1
2ZERO 3
3JUMP 2 3 12
4ZERO 4
5JUMP 3 4 9
6SUCC 1
7SUCC 4
8ZERO 5
9JUMP 5 5 4
10SUCC 3
11ZERO 6
12JUMP 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 @@
1COMMENT Compute sum 1 + 3 + 5 + ... + n, where n is the greatest
2COMMENT integer less or equal to the initial value of Register 1.
3
4COMMENT Initialization
5ZERO 2
6INC 2
7ZERO 3
8
9COMMENT Main loop
10LABEL loop
11EQ? 2 1 continue
12GEQ? 2 1 done
13LABEL continue
14ADD 3 2
15INC 2
16INC 2
17GOTO loop
18
19LABEL done
20COPY 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 @@
1ZERO 2
2SUCC 2
3ZERO 3
4JUMP 2 1 10
5ZERO 4
6JUMP 2 4 10
7JUMP 1 4 20
8SUCC 4
9ZERO 6
10JUMP 6 6 5
11ZERO 5
12JUMP 2 5 16
13SUCC 3
14SUCC 5
15ZERO 7
16JUMP 7 7 11
17SUCC 2
18SUCC 2
19ZERO 8
20JUMP 8 8 3
21COPY 1 3