1
+ OutFile("Loops.exe");
2
+ ShowInstDetails("show");
3
+ XPStyle("on");
4
+ RequestExecutionLevel("admin");
5
+
6
+ section Loops()
7
+ {
8
+ DetailPrint("For Loop 1");
9
+ for ($i = 0, $j = 10; $i < 5 || $j > 0; $i++, $j--)
10
+ {
11
+ DetailPrint("$i = ".$i." and $j = ".$j);
12
+ }
13
+
14
+ DetailPrint("For Loop 2");
15
+ for ($i = 0, $j = 10; $i < 5 && $j > 0; $i++, $j--)
16
+ {
17
+ DetailPrint("$i = ".$i." and $j = ".$j);
18
+ }
19
+
20
+ /* Currently even though the code below is not assembled, $k will
21
+ * still get declared and if $k is not used elsewhere in the script,
22
+ * $k will be wasting run-time memory. To fix, the assembler will need
23
+ * to remove $k from the variables list if it is not already used
24
+ * prior to its use here.
25
+ */
26
+ DetailPrint("For Loop 3 (never gets assembled)");
27
+ for ($k = 0; true && false; $k++)
28
+ {
29
+ DetailPrint("$k = ".$k);
30
+ }
31
+
32
+ DetailPrint("For Loop 4");
33
+ $m = 5;
34
+ for (; $m >= 0;)
35
+ {
36
+ DetailPrint("$m = ".$m);
37
+ if (true)
38
+ $m--;
39
+ }
40
+
41
+ DetailPrint("For Loop 5 (same as Loop 4)");
42
+ $m = 5;
43
+ for (;;)
44
+ {
45
+ DetailPrint("$m = ".$m);
46
+ if ($m > 0)
47
+ {
48
+ $m--;
49
+ continue;
50
+ }
51
+ break;
52
+ }
53
+
54
+ DetailPrint("While Loop 1");
55
+ $i = 0;
56
+ while ($i < 9)
57
+ {
58
+ DetailPrint("$i = ".$i);
59
+ $i++;
60
+ }
61
+
62
+ /* Currently this IS assembled even though it will never execute.
63
+ * Further optimisations could be done here if there are no
64
+ * assignments or function calls on the left hand side of the && (as
65
+ * is the case). That however would require a walk of its parse tree
66
+ * or new code to propogate down the parse tree that there are
67
+ * assignments or method calls within the tree.
68
+ */
69
+ DetailPrint("While Loop 2");
70
+ while ($i < 9 && false)
71
+ {
72
+ DetailPrint("$i = ".$i);
73
+ $i++;
74
+ }
75
+
76
+ DetailPrint("Do While Loop 1");
77
+ $i = 0;
78
+ do
79
+ {
80
+ DetailPrint("$i = ".$i);
81
+ $i++;
82
+ }
83
+ while ($i < 5);
84
+
85
+ /* Because this only executes once we end up with an unused go-to
86
+ * label at the top. We cannot simply remove it because of
87
+ * while(false), as there may well be a 'continue' statement inside
88
+ * that wants to use the label. Because the assembler writes the
89
+ * output in a single pass, it is not possible to back-track and
90
+ * remove the label at a later date. Instead, and because the makensis
91
+ * compiler issues a "label not used" message, we are forced to
92
+ * reference the label with StrCmp "" "" 0 [label]. The zero-jump will
93
+ * always be taken of course.
94
+ */
95
+ DetailPrint("Do While Loop 2");
96
+ $i = 0;
97
+ do
98
+ {
99
+ DetailPrint("This appears once only");
100
+ }
101
+ while (false);
102
+ }
0 commit comments