diff options
author | pacien | 2018-04-30 23:21:17 +0200 |
---|---|---|
committer | pacien | 2018-04-30 23:21:17 +0200 |
commit | 37716a32c9aadcca83746bf96bf32b552fa55847 (patch) | |
tree | 0863035615645c376f3e7fa85d6b4b8de2354e84 | |
parent | 720ffc02dc4d8614b1f8c3c31dd161984b1c6642 (diff) | |
download | urm-37716a32c9aadcca83746bf96bf32b552fa55847.tar.gz |
Add examples from S.V website
-rw-r--r-- | examples/add.eurm | 3 | ||||
-rw-r--r-- | examples/add.urm | 16 | ||||
-rw-r--r-- | examples/even.eurm | 25 | ||||
-rw-r--r-- | examples/even.reg | 1 | ||||
-rw-r--r-- | examples/even.urm | 11 | ||||
-rw-r--r-- | examples/factorial.eurm | 12 | ||||
-rw-r--r-- | examples/factorial.urm | 30 | ||||
-rw-r--r-- | examples/sum-first-integers.eurm | 16 | ||||
-rw-r--r-- | examples/sum-first-integers.reg | 1 | ||||
-rw-r--r-- | examples/sum-first-integers.urm | 12 | ||||
-rw-r--r-- | examples/sum-first-odd-integers.eurm | 20 | ||||
-rw-r--r-- | examples/sum-first-odd-integers.reg | 1 | ||||
-rw-r--r-- | examples/sum-first-odd-integers.urm | 21 |
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 @@ | |||
1 | COMMENT Add the content of registers 1 and 2. | ||
2 | |||
3 | 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 @@ | |||
1 | ZERO 0 | 1 | Zero 3 |
2 | ZERO 3 | 2 | Jump 2 3 5 |
3 | JUMP 1 3 6 | 3 | Succ 1 |
4 | SUCC 0 | 4 | Succ 3 |
5 | SUCC 3 | 5 | Jump 1 1 1 |
6 | JUMP 3 3 2 | ||
7 | ZERO 3 | ||
8 | JUMP 2 3 11 | ||
9 | SUCC 0 | ||
10 | SUCC 3 | ||
11 | JUMP 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 @@ | |||
1 | COMMENT Decide wether the content of Register 1 is even. | ||
2 | COMMENT The output is 0 if it is even and 1 otherwise | ||
3 | |||
4 | COMMENT initialization | ||
5 | ZERO 2 | ||
6 | |||
7 | COMMENT main loop | ||
8 | LABEL loop | ||
9 | COMMENT invariant: R2 is even | ||
10 | EQ? 1 2 even | ||
11 | INC 2 | ||
12 | COMMENT invariant: R2 is odd | ||
13 | EQ? 1 2 odd | ||
14 | INC 2 | ||
15 | GOTO loop | ||
16 | |||
17 | COMMENT R1 holds an even number | ||
18 | LABEL even | ||
19 | ZERO 1 | ||
20 | QUIT | ||
21 | |||
22 | COMMENT R1 holds an odd number | ||
23 | LABEL odd | ||
24 | ZERO 1 | ||
25 | 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 @@ | |||
1 | ZERO 2 | ||
2 | JUMP 1 2 7 | ||
3 | SUCC 2 | ||
4 | JUMP 1 2 9 | ||
5 | SUCC 2 | ||
6 | ZERO 3 | ||
7 | JUMP 3 3 1 | ||
8 | ZERO 1 | ||
9 | JUMP 1 1 11 | ||
10 | ZERO 1 | ||
11 | 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 @@ | |||
1 | COMMENT compute |R1| ! and place the result in register R1. | 1 | COMMENT Compute R1! and place the result in R1 |
2 | |||
2 | ZERO? 1 R1=0 | 3 | ZERO? 1 R1=0 |
3 | GOTO R1>0 | 4 | GOTO R1>0 |
4 | COMMENT R1=0, we are done as 0 ! = 1. | 5 | |
6 | COMMENT R1 holds 0 | ||
5 | LABEL R1=0 | 7 | LABEL R1=0 |
6 | INC 1 | 8 | INC 1 |
7 | GOTO done | 9 | GOTO done |
8 | COMMENT R1>0, use n ! = 1 x 2 x ... x n | 10 | |
11 | COMMENT R1 holds a positive integer | ||
9 | LABEL R1>0 | 12 | LABEL R1>0 |
10 | COPY 2 1 | 13 | COPY 2 1 |
11 | ZERO 1 | 14 | ZERO 1 |
12 | INC 1 | 15 | INC 1 |
13 | ZERO 3 | 16 | ZERO 3 |
14 | INC 3 | 17 | INC 3 |
18 | |||
15 | COMMENT main loop | 19 | COMMENT main loop |
16 | LABEL loop | 20 | LABEL loop |
17 | MULT 1 3 | 21 | MULT 1 3 |
18 | EQ? 2 3 done | 22 | EQ? 2 3 done |
19 | INC 3 | 23 | INC 3 |
20 | GOTO loop | 24 | GOTO loop |
21 | COMMENT that’s all folks. | 25 | |
22 | LABEL done | 26 | LABEL done |
23 | QUIT | 27 | 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 @@ | |||
1 | ZERO 4 | ||
2 | JUMP 1 4 4 | ||
3 | ZERO 8 | ||
4 | JUMP 8 8 7 | ||
5 | Succ 1 | ||
6 | ZERO 9 | ||
7 | JUMP 9 9 29 | ||
8 | COPY 2 1 | ||
9 | ZERO 1 | ||
10 | Succ 1 | ||
11 | ZERO 3 | ||
12 | Succ 3 | ||
13 | COPY 6 1 | ||
14 | ZERO 1 | ||
15 | ZERO 5 | ||
16 | JUMP 3 5 25 | ||
17 | ZERO 7 | ||
18 | JUMP 6 7 22 | ||
19 | Succ 1 | ||
20 | Succ 7 | ||
21 | ZERO 10 | ||
22 | JUMP 10 10 17 | ||
23 | Succ 5 | ||
24 | ZERO 11 | ||
25 | JUMP 11 11 15 | ||
26 | JUMP 2 3 29 | ||
27 | Succ 3 | ||
28 | ZERO 12 | ||
29 | JUMP 12 12 12 | ||
30 | 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 @@ | |||
1 | COMMENT Put in Register 1 the sum 1 + 2 + ... + n, | ||
2 | COMMENT where n is the initial value of Register 1. | ||
3 | |||
4 | COMMENT Initialization | ||
5 | COPY 2 1 | ||
6 | ZERO 3 | ||
7 | |||
8 | COMMENT Main loop | ||
9 | LABEL loop | ||
10 | EQ? 2 3 done | ||
11 | ADD 1 3 | ||
12 | INC 3 | ||
13 | GOTO loop | ||
14 | |||
15 | COMMENT That's all folks ! | ||
16 | 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 @@ | |||
1 | COPY 2 1 | ||
2 | ZERO 3 | ||
3 | JUMP 2 3 12 | ||
4 | ZERO 4 | ||
5 | JUMP 3 4 9 | ||
6 | SUCC 1 | ||
7 | SUCC 4 | ||
8 | ZERO 5 | ||
9 | JUMP 5 5 4 | ||
10 | SUCC 3 | ||
11 | ZERO 6 | ||
12 | 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 @@ | |||
1 | COMMENT Compute sum 1 + 3 + 5 + ... + n, where n is the greatest | ||
2 | COMMENT integer less or equal to the initial value of Register 1. | ||
3 | |||
4 | COMMENT Initialization | ||
5 | ZERO 2 | ||
6 | INC 2 | ||
7 | ZERO 3 | ||
8 | |||
9 | COMMENT Main loop | ||
10 | LABEL loop | ||
11 | EQ? 2 1 continue | ||
12 | GEQ? 2 1 done | ||
13 | LABEL continue | ||
14 | ADD 3 2 | ||
15 | INC 2 | ||
16 | INC 2 | ||
17 | GOTO loop | ||
18 | |||
19 | LABEL done | ||
20 | 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 @@ | |||
1 | ZERO 2 | ||
2 | SUCC 2 | ||
3 | ZERO 3 | ||
4 | JUMP 2 1 10 | ||
5 | ZERO 4 | ||
6 | JUMP 2 4 10 | ||
7 | JUMP 1 4 20 | ||
8 | SUCC 4 | ||
9 | ZERO 6 | ||
10 | JUMP 6 6 5 | ||
11 | ZERO 5 | ||
12 | JUMP 2 5 16 | ||
13 | SUCC 3 | ||
14 | SUCC 5 | ||
15 | ZERO 7 | ||
16 | JUMP 7 7 11 | ||
17 | SUCC 2 | ||
18 | SUCC 2 | ||
19 | ZERO 8 | ||
20 | JUMP 8 8 3 | ||
21 | COPY 1 3 | ||