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