1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 == code
18
19
20
21
22
23
24 8b/copy 0/mod/indirect 4/rm32/sib 4/base/ESP 4/index/none . 0/r32/EAX . .
25 3d/compare . . . . . . . 1/imm32
26 7e/jump-if-lesser-or-equal $run_main/disp8
27
28 8b/copy 1/mod/*+disp8 4/rm32/sib 4/base/ESP 4/index/none . 0/r32/EAX 8/disp8 .
29
30 50/push-EAX
31 68/push "test"/imm32
32
33 e8/call argv_equal/disp32
34
35 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
36
37 3d/compare . . . . . . . 1/imm32
38 75/jump-if-not-equal $run_main/disp8
39
40 e8/call run_tests/disp32
41 eb/jump $main_exit/disp8
42
43 $run_main:
44
45 68/push 5/imm32
46
47 e8/call factorial/disp32
48
49 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
50 $main_exit:
51
52 89/copy 3/mod/direct 3/rm32/EBX . . . 0/r32/EAX . .
53 b8/copy . . . . . . . 1/imm32
54 cd/syscall 0x80/imm8
55
56
57 factorial:
58
59 b8/copy . . . . . . . 1/imm32
60
61 81 7/subop/compare 1/mod/*+disp8 4/rm32/sib 4/base/ESP 4/index/none . . 4/disp8 1/imm32
62 7e/jump-if-<= $factorial:exit/disp8
63
64 8b/copy 1/mod/*+disp8 4/rm32/sib 4/base/ESP 4/index/none 3/r32/EBX 4/disp8 .
65 81 5/subop/subtract 3/mod/direct 3/rm32/EBX . . . . . 1/imm32
66
67 55/push-EBP
68 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
69
70 53/push-EBX
71 e8/call . . . . . . factorial/disp32
72
73 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
74
75 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
76 5d/pop . . . . . . . .
77
78 8b/copy 1/mod/*+disp8 4/rm32/sib 4/base/ESP 4/index/none 2/r32/EDX 4/disp8 .
79
80 f7 4/subop/multiply 1/mod/*+disp8 4/rm32/sib 4/base/ESP 4/index/none 4/disp8 .
81
82 $factorial:exit:
83 c3/return
84
85 test_factorial:
86
87
88 68/push 5/imm32
89
90 e8/call factorial/disp32
91
92 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
93
94
95 50/push-EAX
96 68/push 0x78/imm32/expected-120
97 68/push "F - test_factorial"/imm32
98
99 e8/call check_ints_equal/disp32
100
101 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
102
103 c3/return
104
105
106
107
108 check_ints_equal:
109
110 8b/copy 1/mod/*+disp8 4/rm32/sib 4/base/ESP 4/index/none . 0/r32/EAX 0xc/disp8 .
111 8b/copy 1/mod/*+disp8 4/rm32/sib 4/base/ESP 4/index/none . 3/r32/EBX 0x8/disp8 .
112
113 39/compare 3/mod/direct 0/rm32/EAX . . . 3/r32/EBX . .
114 75/jump-if-unequal $check_ints_equal:else/disp8
115
116
117 68/push "."/imm32
118
119 e8/call write_stderr/disp32
120
121 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
122
123 c3/return
124
125 $check_ints_equal:else:
126
127 8b/copy 1/mod/*+disp8 4/rm32/sib 4/base/ESP 4/index/none . 1/r32/ECX 4/disp8 .
128
129
130 51/push-ECX
131
132 e8/call write_stderr/disp32
133
134 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
135
136
137 68/push Newline/imm32
138
139 e8/call write_stderr/disp32
140
141 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
142
143 c3/return
144
145
146
147 argv_equal:
148
149
150
151
152
153
154
155
156
157
158
159
160
161 +-- 45 lines: # --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
206 +--134 lines: # tests for argv_equal -----------------------------------------------------------------------------------------------------------------------------------------------------------------------
340
341 write_stderr:
342
343 50/push-EAX
344 51/push-ECX
345 52/push-EDX
346 53/push-EBX
347
348
349 bb/copy . . . . . . . 2/imm32
350
351 8b/copy 1/mod/*+disp8 4/rm32/SIB 4/base/ESP 4/index/none . 1/r32/ECX 0x14/disp8 .
352 81 0/subop/add 3/mod/direct 1/rm32/ECX . . . . . 4/imm32
353
354 8b/copy 1/mod/*+disp8 4/rm32/SIB 4/base/ESP 4/index/none . 2/r32/EDX 0x14/disp8 .
355 8b/copy 0/mod/indirect 2/rm32/EDX . . . 2/r32/EDX . .
356
357 b8/copy . . . . . . . 4/imm32/write
358 cd/syscall 0x80/imm8
359
360 5b/pop-EBX
361 5a/pop-EDX
362 59/pop-ECX
363 58/pop-EAX
364
365 c3/return
366
367 == data
368 Newline:
369
370 01 00 00 00
371
372 0a/newline
373
374
375 Null_argv:
376 00/null
377 Abc_argv:
378 41/A 62/b 63/c 00/null
379
380