about summary refs log tree commit diff stats
path: root/subx/examples/ex11.subx
diff options
context:
space:
mode:
Diffstat (limited to 'subx/examples/ex11.subx')
-rw-r--r--subx/examples/ex11.subx38
1 files changed, 19 insertions, 19 deletions
diff --git a/subx/examples/ex11.subx b/subx/examples/ex11.subx
index 253b91ab..e2628c39 100644
--- a/subx/examples/ex11.subx
+++ b/subx/examples/ex11.subx
@@ -1,4 +1,4 @@
-## Null-terminated vs length-prefixed ascii strings.
+# Null-terminated vs length-prefixed ascii strings.
 #
 # By default we create strings with a 4-byte length prefix rather than a null suffix.
 # However we still need null-prefixed strings when interacting with the Linux
@@ -108,7 +108,7 @@ $kernel-string-equal:end:
     5d/pop-to-EBP
     c3/return
 
-## tests
+# - tests
 
 test-compare-null-kernel-string-with-empty-array:
     # EAX = kernel-string-equal(Null-kernel-string, "")
@@ -119,7 +119,7 @@ test-compare-null-kernel-string-with-empty-array:
     e8/call  kernel-string-equal/disp32
     # . . discard args
     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
-    # . . call check-ints-equal(EAX, 1, msg)
+    # check-ints-equal(EAX, 1, msg)
     # . . push args
     68/push  "F - test-compare-null-kernel-string-with-empty-array"/imm32
     68/push  1/imm32/true
@@ -139,7 +139,7 @@ test-compare-null-kernel-string-with-non-empty-array:
     e8/call  kernel-string-equal/disp32
     # . . discard args
     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
-    # . . call check-ints-equal(EAX, 0, msg)
+    # check-ints-equal(EAX, 0, msg)
     # . . push args
     68/push  "F - test-compare-null-kernel-string-with-non-empty-array"/imm32
     68/push  0/imm32/false
@@ -159,7 +159,7 @@ test-compare-kernel-string-with-equal-array:
     e8/call  kernel-string-equal/disp32
     # . . discard args
     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
-    # . . call check-ints-equal(EAX, 1, msg)
+    # check-ints-equal(EAX, 1, msg)
     # . . push args
     68/push  "F - test-compare-kernel-string-with-equal-array"/imm32
     68/push  1/imm32/true
@@ -179,7 +179,7 @@ test-compare-kernel-string-with-inequal-array:
     e8/call  kernel-string-equal/disp32
     # . . discard args
     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
-    # . . call check-ints-equal(EAX, 0, msg)
+    # check-ints-equal(EAX, 0, msg)
     # . . push args
     68/push  "F - test-compare-kernel-string-with-equal-array"/imm32
     68/push  0/imm32/false
@@ -199,7 +199,7 @@ test-compare-kernel-string-with-empty-array:
     e8/call  kernel-string-equal/disp32
     # . . discard args
     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
-    # . . call check-ints-equal(EAX, 0)
+    # check-ints-equal(EAX, 0)
     # . . push args
     68/push  "F - test-compare-kernel-string-with-equal-array"/imm32
     68/push  0/imm32/false
@@ -219,7 +219,7 @@ test-compare-kernel-string-with-shorter-array:
     e8/call  kernel-string-equal/disp32
     # . . discard args
     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
-    # . . call check-ints-equal(EAX, 0)
+    # check-ints-equal(EAX, 0)
     # . . push args
     68/push  "F - test-compare-kernel-string-with-shorter-array"/imm32
     68/push  0/imm32/false
@@ -239,7 +239,7 @@ test-compare-kernel-string-with-longer-array:
     e8/call  kernel-string-equal/disp32
     # . . discard args
     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
-    # . . call check-ints-equal(EAX, 0)
+    # check-ints-equal(EAX, 0)
     # . . push args
     68/push  "F - test-compare-kernel-string-with-longer-array"/imm32
     68/push  0/imm32/false
@@ -250,7 +250,7 @@ test-compare-kernel-string-with-longer-array:
     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               0xc/imm32         # add to ESP
     c3/return
 
-## helpers
+# - helpers
 
 # print msg to stderr if a != b, otherwise print "."
 check-ints-equal:  # (a : int, b : int, msg : (address array byte)) -> boolean
@@ -263,19 +263,19 @@ check-ints-equal:  # (a : int, b : int, msg : (address array byte)) -> boolean
     # load args into EAX, EBX and ECX
     8b/copy                         1/mod/*+disp8   4/rm32/sib    5/base/EBP  4/index/none  .           0/r32/EAX   0x8/disp8       .                 # copy *(EBP+8) to EAX
     8b/copy                         1/mod/*+disp8   4/rm32/sib    5/base/EBP  4/index/none  .           3/r32/EBX   0xc/disp8       .                 # copy *(EBP+12) to EBX
-    # if EAX == b/EBX
+    # if EAX == b/EBX print('.') and return
     39/compare                      3/mod/direct    0/rm32/EAX    .           .             .           3/r32/EBX   .               .                 # compare EAX and EBX
     75/jump-if-unequal  $check-ints-equal:else/disp8
-    # print('.')
+    # . write-stderr('.')
     # . . push args
     68/push  "."/imm32
     # . . call
     e8/call  write-stderr/disp32
     # . . discard args
     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               4/imm32           # add to ESP
-    # return
+    # . return
     eb/jump  $check-ints-equal:end/disp8
-    # else:
+    # otherwise print(msg)
 $check-ints-equal:else:
     # copy msg into ECX
     8b/copy                         1/mod/*+disp8   4/rm32/sib    5/base/EBP  4/index/none  .           1/r32/ECX   0x10/disp8       .                # copy *(EBP+16) to ECX
@@ -312,15 +312,15 @@ write-stderr:  # s : (address array byte) -> <void>
     52/push-EDX
     53/push-EBX
     # syscall(write, 2/stderr, (data) s+4, (size) *s)
-    # fd = 2 (stderr)
+    # . . fd = 2 (stderr)
     bb/copy-to-EBX  2/imm32
-    # x = s+4
+    # . . x = s+4
     8b/copy                         1/mod/*+disp8   4/rm32/sib    5/base/EBP  4/index/none  .           1/r32/ECX   8/disp8         .                 # copy *(EBP+8) to ECX
     81          0/subop/add         3/mod/direct    1/rm32/ECX    .           .             .           .           .               4/imm32           # add to ECX
-    # size = *s
+    # . . size = *s
     8b/copy                         1/mod/*+disp8   4/rm32/sib    5/base/EBP  4/index/none  .           2/r32/EDX   8/disp8         .                 # copy *(EBP+8) to EDX
     8b/copy                         0/mod/indirect  2/rm32/EDX    .           .             .           2/r32/EDX   .               .                 # copy *EDX to EDX
-    # syscall
+    # . . syscall
     b8/copy-to-EAX  4/imm32/write
     cd/syscall  0x80/imm8
     # . restore registers
@@ -328,7 +328,7 @@ write-stderr:  # s : (address array byte) -> <void>
     5a/pop-to-EDX
     59/pop-to-ECX
     58/pop-to-EAX
-    # end
+    # . end
     89/copy                         3/mod/direct    4/rm32/ESP    .           .             .           5/r32/EBP   .               .                 # copy EBP to ESP
     5d/pop-to-EBP
     c3/return
67f85529be15e0456b3169'>dc1323e9 ^
6c96a437 ^
795f5244 ^
e6692482 ^
fa6d93b2 ^
2b250717 ^
fa6d93b2 ^

4071055a ^
dc1323e9 ^
e6692482 ^
fa6d93b2 ^
2b250717 ^
fa6d93b2 ^

4071055a ^
dc1323e9 ^
e6692482 ^
fa6d93b2 ^
4071055a ^
dc1323e9 ^
e6692482 ^

fa6d93b2 ^
4071055a ^
dc1323e9 ^



b24eb476 ^
e4630643 ^
9dcbec39 ^
4adb09bc ^
e4630643 ^

ef96f57c ^
0f125d5f ^
4adb09bc ^
9dcbec39 ^
4adb09bc ^


f3760b0f ^
9dcbec39 ^
4adb09bc ^


f22250a1 ^
dc1323e9 ^


1ead3562 ^
dc1323e9 ^

8ba8f0f6 ^
192d59d3 ^
dc1323e9 ^






1ead3562 ^
dc1323e9 ^

bc643692 ^
192d59d3 ^
dc1323e9 ^






1ead3562 ^
dc1323e9 ^

bc643692 ^
192d59d3 ^
dc1323e9 ^




4071055a ^

1ead3562 ^
4071055a ^
192d59d3 ^


8ba8f0f6 ^
192d59d3 ^
4071055a ^
192d59d3 ^
4071055a ^


4adb09bc ^
fa6d93b2 ^

1ead3562 ^
fa6d93b2 ^

e62aa7e3 ^
fa6d93b2 ^


1ead3562 ^
dd660682 ^
fa6d93b2 ^
dd660682 ^
fa6d93b2 ^
5f98a10c ^

1ead3562 ^
4adb09bc ^
192d59d3 ^
4adb09bc ^
192d59d3 ^
4adb09bc ^
5f98a10c ^
4adb09bc ^

5f98a10c ^
1ead3562 ^
4adb09bc ^
192d59d3 ^


4adb09bc ^
192d59d3 ^
4adb09bc ^
192d59d3 ^
4adb09bc ^
9dcbec39 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183