You are on page 1of 5

Results :

High Level Language Code Assembly Code


1 i = 2; 0 push 2
if(i==1) 5 store [0]
{ 10 fetch [0]
print(i); 15 push 1
} 20 eq
elif(i==2) 21 jz (10) 32
{ 26 fetch [0]
print(i); 31 prti
} 32 fetch [0]
elif(i==3) 37 push 2
{ 42 eq
print(i); 43 jz (10) 54
} 48 fetch [0]
53 prti
54 fetch [0]
59 push 3
64 eq
65 jz (10) 76
70 fetch [0]
75 prti
76 halt
2 count = 1; 0 push 1
while (count < 10) { 5 store [0]
print("count is: ", count, "\n"); 10 fetch [0]
count = count + 1; 15 push 10
} 20 lt
21 jz (43) 65
26 push 0
31 prts
32 fetch [0]
37 prti
38 push 1
43 prts
44 fetch [0]
49 push 1
54 add
55 store [0]
60 jmp (-51) 10
65 halt
3 if(p){print(n," ");count=count+1;} 0 fetch [0]
5 jz (32) 38
10 fetch [1]
15 prti
16 push 0
21 prts
22 fetch [2]
27 push 1
32 add
33 store [2]
38 halt
4 print(42); 0 push 42
print("\nHello World\nGood Bye\nok\n"); 5 prti
print("Print a slash n - \\n.\n"); 6 push 0
11 prts
12 push 1
17 prts
18 halt
5 print("Hello, World!\n"); 0 push 0
5 prts
6 halt
6 i = 1; 0 push 1
while (i * i <= 100) { 5 store [0]
print("door ", i * i, " is open\n"); 10 fetch [0]
i = i + 1; 15 fetch [0]
} 20 mul
21 push 100
26 le
27 jz (49) 77
32 push 0
37 prts
38 fetch [0]
43 fetch [0]
48 mul
49 prti
50 push 1
55 prts
56 fetch [0]
61 push 1
66 add
67 store [0]
72 jmp (-63) 10
77 halt
7 a = (-1 * ((-1 * (5 * 15)) / 10)); 0 push 1
print(a, "\n"); 5 neg
b = -a; 6 push 1
print(b, "\n"); 11 neg
print(-b, "\n"); 12 push 5
print(-(1), "\n"); 17 push 15
22 mul
23 mul
24 push 10
29 div
30 mul
31 store [0]
36 fetch [0]
41 prti
42 push 0
47 prts
48 fetch [0]
53 neg
54 store [1]
59 fetch [1]
64 prti
65 push 0
70 prts
71 fetch [1]
76 neg
77 prti
78 push 0
83 prts
84 push 1
89 neg
90 prti
91 push 0
96 prts
97 halt
8 print(---------------------------------+++5, "\n"); 0 push 5
print(((((((((3 + 2) * ((((((2))))))))))))), "\n"); 5 neg
6 neg
if (1) { if (1) { if (1) { if (1) { if (1) 7 neg
{ print(15, "\n"); } } } } } 8 neg
9 neg
10 neg
11 neg
12 neg
13 neg
14 neg
15 neg
16 neg
17 neg
18 neg
19 neg
20 neg
21 neg
22 neg
23 neg
24 neg
25 neg
26 neg
27 neg
28 neg
29 neg
30 neg
31 neg
32 neg
33 neg
34 neg
35 neg
36 neg
37 neg
38 prti
39 push 0
44 prts
45 push 3
50 push 2
55 add
56 push 2
61 mul
62 prti
63 push 0
68 prts
69 push 1
74 jz (56) 131
79 push 1
84 jz (46) 131
89 push 1
94 jz (36) 131
99 push 1
104 jz (26) 131
109 push 1
114 jz (16) 131
119 push 15
124 prti
125 push 0
130 prts
131 halt
9 0 push 1071
/* Compute the gcd of 1071, 1029: 21 */ 5 store [0]
10 push 1029
a = 1071; 15 store [1]
b = 1029; 20 fetch [1]
25 push 0
while (b != 0) { 30 ne
new_a = b; 31 jz (45) 77
b = a % b; 36 fetch [1]
a = new_a; 41 store [2]
} 46 fetch [0]
print(a); 51 fetch [1]
56 mod
57 store [1]
62 fetch [2]
67 store [0]
72 jmp (-53) 20
77 fetch [0]
82 prti
83 halt
10 /* 12 factorial is 479001600 */ 0 push 12
5 store [0]
n = 12; 10 push 1
result = 1; 15 store [1]
i = 1; 20 push 1
while (i <= n) { 25 store [2]
result = result * i; 30 fetch [2]
i = i + 1; 35 fetch [0]
} 40 le
print(result); 41 jz (41) 83
46 fetch [1]
51 fetch [2]
56 mul
57 store [1]
62 fetch [2]
67 push 1
72 add
73 store [2]
78 jmp (-49) 30
83 fetch [1]
88 prti
89 halt

You might also like