-
Notifications
You must be signed in to change notification settings - Fork 0
/
fact.s
169 lines (169 loc) · 2.12 KB
/
fact.s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
.section .data
prnt_int:
.asciz "%d\n"
.section .text
fact:
movl 4(%esp), %ecx
movl $1, %eax
cmpb $0,%cl
jle done
do_fact:
mull %ecx
cmpb $0,%cl
dec %ecx
jle done
jmp do_fact
done:
ret
.global main
main:
pushl %ebp
movl %esp, %ebp
sub $100, %esp
pushl $0
call fact
addl $4,%esp
pushl %eax
pushl $1
popl %ebx
popl %eax
subl %ebx, %eax
pushl %eax
pushl $prnt_int
call printf
addl $8, %esp
pushl $1
call fact
addl $4,%esp
pushl %eax
pushl $1
popl %ebx
popl %eax
subl %ebx, %eax
pushl %eax
pushl $prnt_int
call printf
addl $8, %esp
pushl $2
call fact
addl $4,%esp
pushl %eax
pushl $2
popl %ebx
popl %eax
subl %ebx, %eax
pushl %eax
pushl $prnt_int
call printf
addl $8, %esp
pushl $3
call fact
addl $4,%esp
pushl %eax
pushl $6
popl %ebx
popl %eax
subl %ebx, %eax
pushl %eax
pushl $prnt_int
call printf
addl $8, %esp
pushl $4
call fact
addl $4,%esp
pushl %eax
pushl $24
popl %ebx
popl %eax
subl %ebx, %eax
pushl %eax
pushl $prnt_int
call printf
addl $8, %esp
pushl $5
call fact
addl $4,%esp
pushl %eax
pushl $120
popl %ebx
popl %eax
subl %ebx, %eax
pushl %eax
pushl $prnt_int
call printf
addl $8, %esp
pushl $6
call fact
addl $4,%esp
pushl %eax
pushl $720
popl %ebx
popl %eax
subl %ebx, %eax
pushl %eax
pushl $prnt_int
call printf
addl $8, %esp
pushl $7
call fact
addl $4,%esp
pushl %eax
pushl $5040
popl %ebx
popl %eax
subl %ebx, %eax
pushl %eax
pushl $prnt_int
call printf
addl $8, %esp
pushl $8
call fact
addl $4,%esp
pushl %eax
pushl $40320
popl %ebx
popl %eax
subl %ebx, %eax
pushl %eax
pushl $prnt_int
call printf
addl $8, %esp
pushl $9
call fact
addl $4,%esp
pushl %eax
pushl $362880
popl %ebx
popl %eax
subl %ebx, %eax
pushl %eax
pushl $prnt_int
call printf
addl $8, %esp
pushl $10
call fact
addl $4,%esp
pushl %eax
pushl $3628800
popl %ebx
popl %eax
subl %ebx, %eax
pushl %eax
pushl $prnt_int
call printf
addl $8, %esp
pushl $11
call fact
addl $4,%esp
pushl %eax
pushl $39916800
popl %ebx
popl %eax
subl %ebx, %eax
pushl %eax
pushl $prnt_int
call printf
addl $8, %esp
movl %ebp, %esp
popl %ebp
call exit