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