Skip to content

Commit a72f496

Browse files
adding examples
1 parent c1cfa5f commit a72f496

File tree

6 files changed

+200
-0
lines changed

6 files changed

+200
-0
lines changed

e1.tm

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
* TINY Compilation to TM Code
2+
* File: e1.tm
3+
* Standard prelude:
4+
0: LD 6,0(0) load maxaddress from location 0
5+
1: ST 0,0(0) clear location 0
6+
* End of standard prelude.
7+
2: IN 0,0,0 read integer value
8+
3: ST 0,0(5) read: store value
9+
4: IN 0,0,0 read integer value
10+
5: ST 0,1(5) read: store value
11+
* -> while
12+
* -> Op
13+
* -> Id
14+
6: LD 0,1(5) load id value
15+
* <- Id
16+
7: ST 0,0(6) op: push left
17+
* -> Const
18+
8: LDC 0,5(0) load const
19+
* <- Const
20+
9: LD 1,0(6) op: load left
21+
10: SUB 0,1,0 op <
22+
11: JLT 0,2(7) br if true
23+
12: LDC 0,0(0) false case
24+
13: LDA 7,1(7) unconditional jmp
25+
14: LDC 0,1(0) true case
26+
* <- Op
27+
* -> while
28+
* -> Op
29+
* -> Id
30+
16: LD 0,0(5) load id value
31+
* <- Id
32+
17: ST 0,0(6) op: push left
33+
* -> Const
34+
18: LDC 0,10(0) load const
35+
* <- Const
36+
19: LD 1,0(6) op: load left
37+
20: SUB 0,1,0 op <
38+
21: JLT 0,2(7) br if true
39+
22: LDC 0,0(0) false case
40+
23: LDA 7,1(7) unconditional jmp
41+
24: LDC 0,1(0) true case
42+
* <- Op
43+
* -> assign
44+
* -> Op
45+
* -> Id
46+
26: LD 0,0(5) load id value
47+
* <- Id
48+
27: ST 0,0(6) op: push left
49+
* -> Const
50+
28: LDC 0,1(0) load const
51+
* <- Const
52+
29: LD 1,0(6) op: load left
53+
30: ADD 0,1,0 op +
54+
* <- Op
55+
31: ST 0,0(5) assign: store value
56+
* <- assign
57+
* -> Id
58+
32: LD 0,0(5) load id value
59+
* <- Id
60+
33: OUT 0,0,0 write ac
61+
34: LDA 7,-19(7) while: jump after body comes back here
62+
25: JEQ 0,9(7) while: jump back to body
63+
* <- while
64+
* -> assign
65+
* -> Op
66+
* -> Id
67+
35: LD 0,1(5) load id value
68+
* <- Id
69+
36: ST 0,0(6) op: push left
70+
* -> Const
71+
37: LDC 0,1(0) load const
72+
* <- Const
73+
38: LD 1,0(6) op: load left
74+
39: ADD 0,1,0 op +
75+
* <- Op
76+
40: ST 0,1(5) assign: store value
77+
* <- assign
78+
* -> Id
79+
41: LD 0,1(5) load id value
80+
* <- Id
81+
42: OUT 0,0,0 write ac
82+
43: LDA 7,-38(7) while: jump after body comes back here
83+
15: JEQ 0,28(7) while: jump back to body
84+
* <- while
85+
* End of execution.
86+
44: HALT 0,0,0

e1.tny

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
read x;
2+
read y;
3+
while (y<5)
4+
while (x<10)
5+
x:=x+1;
6+
write x
7+
endwhile;
8+
y:=y+1;
9+
write y
10+
endwhile

e2.tm

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
* TINY Compilation to TM Code
2+
* File: e2.tm
3+
* Standard prelude:
4+
0: LD 6,0(0) load maxaddress from location 0
5+
1: ST 0,0(0) clear location 0
6+
* End of standard prelude.
7+
2: IN 0,0,0 read integer value
8+
3: ST 0,0(5) read: store value
9+
* -> while
10+
* -> Op
11+
* -> Id
12+
4: LD 0,0(5) load id value
13+
* <- Id
14+
5: ST 0,0(6) op: push left
15+
* -> Const
16+
6: LDC 0,5(0) load const
17+
* <- Const
18+
7: LD 1,0(6) op: load left
19+
8: SUB 0,1,0 op <
20+
9: JLT 0,2(7) br if true
21+
10: LDC 0,0(0) false case
22+
11: LDA 7,1(7) unconditional jmp
23+
12: LDC 0,1(0) true case
24+
* <- Op
25+
* -> assign
26+
* -> Op
27+
* -> Id
28+
14: LD 0,0(5) load id value
29+
* <- Id
30+
15: ST 0,0(6) op: push left
31+
* -> Const
32+
16: LDC 0,1(0) load const
33+
* <- Const
34+
17: LD 1,0(6) op: load left
35+
18: ADD 0,1,0 op +
36+
* <- Op
37+
19: ST 0,0(5) assign: store value
38+
* <- assign
39+
20: LDA 7,-17(7) while: jump after body comes back here
40+
13: JEQ 0,7(7) while: jump back to body
41+
* <- while
42+
* -> Id
43+
21: LD 0,0(5) load id value
44+
* <- Id
45+
22: OUT 0,0,0 write ac
46+
* End of execution.
47+
23: HALT 0,0,0

e2.tny

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
read x;
2+
while (x<5)
3+
x:=x+1
4+
endwhile;
5+
write x

e3.tm

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
* TINY Compilation to TM Code
2+
* File: e3.tm
3+
* Standard prelude:
4+
0: LD 6,0(0) load maxaddress from location 0
5+
1: ST 0,0(0) clear location 0
6+
* End of standard prelude.
7+
2: IN 0,0,0 read integer value
8+
3: ST 0,0(5) read: store value
9+
* -> while
10+
* -> Op
11+
* -> Id
12+
4: LD 0,0(5) load id value
13+
* <- Id
14+
5: ST 0,0(6) op: push left
15+
* -> Const
16+
6: LDC 0,10(0) load const
17+
* <- Const
18+
7: LD 1,0(6) op: load left
19+
8: SUB 0,1,0 op <
20+
9: JLT 0,2(7) br if true
21+
10: LDC 0,0(0) false case
22+
11: LDA 7,1(7) unconditional jmp
23+
12: LDC 0,1(0) true case
24+
* <- Op
25+
* -> assign
26+
* -> Op
27+
* -> Id
28+
14: LD 0,0(5) load id value
29+
* <- Id
30+
15: ST 0,0(6) op: push left
31+
* -> Const
32+
16: LDC 0,1(0) load const
33+
* <- Const
34+
17: LD 1,0(6) op: load left
35+
18: ADD 0,1,0 op +
36+
* <- Op
37+
19: ST 0,0(5) assign: store value
38+
* <- assign
39+
* -> Id
40+
20: LD 0,0(5) load id value
41+
* <- Id
42+
21: OUT 0,0,0 write ac
43+
22: LDA 7,-19(7) while: jump after body comes back here
44+
13: JEQ 0,9(7) while: jump back to body
45+
* <- while
46+
* End of execution.
47+
23: HALT 0,0,0

e3.tny

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
read x;
2+
while (x<10)
3+
x:=x+1;
4+
write x
5+
endwhile

0 commit comments

Comments
 (0)