https://github.com/akkartik/mu/blob/master/subx/apps/factorial.subx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 == code
17
18
19
20
21
22
23 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
24
25
26 81 7/subop/compare 1/mod/*+disp8 5/rm32/EBP . . . . 0/disp8 1/imm32
27 7e/jump-if-lesser-or-equal $run-main/disp8
28
29
30 68/push "test"/imm32
31 ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 8/disp8 .
32
33 e8/call kernel-string-equal/disp32
34
35 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
36
37 3d/compare-EAX 1/imm32
38 75/jump-if-not-equal $run-main/disp8
39
40 e8/call run-tests/disp32
41 8b/copy 0/mod/indirect 5/rm32/.disp32 . . 0/r32/EAX Num-test-failures/disp32
42 eb/jump $main:end/disp8
43
44 $run-main:
45
46 68/push 5/imm32
47
48 e8/call factorial/disp32
49
50 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
51 $main:end:
52
53 89/copy 3/mod/direct 3/rm32/EBX . . . 0/r32/EAX . .
54 b8/copy-to-EAX 1/imm32/exit
55 cd/syscall 0x80/imm8
56
57 factorial:
58
59 55/push-EBP
60 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
61 53/push-EBX
62
63 b8/copy-to-EAX 1/imm32
64
65 81 7/subop/compare 1/mod/*+disp8 5/rm32/EBP . . . . 8/disp8 1/imm32
66 7e/jump-if-<= $factorial:end/disp8
67
68 8b/copy 1/mod/*+disp8 5/rm32/EBP . . 3/r32/EBX 8/disp8 .
69 81 5/subop/subtract 3/mod/direct 3/rm32/EBX . . . . . 1/imm32
70
71
72 53/push-EBX
73
74 e8/call factorial/disp32
75
76 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
77
78 f7 4/subop/multiply 1/mod/*+disp8 5/rm32/EBP . . 8/disp8 .
79
80 $factorial:end:
81
82 5b/pop-to-EBX
83 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
84 5d/pop-to-EBP
85 c3/return
86
87 test-factorial:
88
89
90 68/push 5/imm32
91
92 e8/call factorial/disp32
93
94 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
95
96
97 68/push "F - test-factorial"/imm32
98 68/push 0x78/imm32/expected-120
99 50/push-EAX
100
101 e8/call check-ints-equal/disp32
102
103 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
104
105 c3/return
106
107