-
Notifications
You must be signed in to change notification settings - Fork 0
/
harmonic.s
73 lines (73 loc) · 934 Bytes
/
harmonic.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
.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 $1000000
popl -56(%ebp)
pushl $100000000
popl -76(%ebp)
pushl $0
popl -4(%ebp)
L000:
pushl -56(%ebp)
pushl $0
popl %edx
popl %eax
cmp %edx, %eax
jle L001
pushl -4(%ebp)
pushl -76(%ebp)
pushl -56(%ebp)
popl %ebx
popl %eax
idivl %ebx
pushl %eax
popl %ebx
popl %eax
addl %ebx, %eax
pushl %eax
popl -4(%ebp)
pushl -56(%ebp)
pushl $1
popl %ebx
popl %eax
subl %ebx, %eax
pushl %eax
popl -56(%ebp)
jmp L000
L001:
pushl -4(%ebp)
pushl -76(%ebp)
pushl $1000
popl %ebx
popl %eax
idivl %ebx
pushl %eax
popl %ebx
popl %eax
idivl %ebx
pushl %eax
pushl $prnt_int
call printf
addl $8, %esp
movl %ebp, %esp
popl %ebp
call exit