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