-
Notifications
You must be signed in to change notification settings - Fork 0
/
simpleio.S
105 lines (93 loc) · 1.9 KB
/
simpleio.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
/* -*- asm -*- */
.extern scanf
.text
_form1: .asciz "%d"
.text
.align 16
readi32:
pushl %ebp
movl %esp, %ebp
subl $4, %esp
leal -4(%ebp), %eax
pushl %eax
pushl $_form1
call scanf
add $8, %esp
movl %eax, %ecx
movl -4(%ebp), %eax
clc
cmpl $1, %ecx
je readi32x
stc
readi32x:
movl %ebp, %esp
popl %ebp
ret
.extern printf
.text
_form2: .asciz "%d"
.text
.align 16
writei32:
pushl %ebp
movl %esp, %ebp
pushl %eax
pushl $_form2
call printf
add $8, %esp
movl %ebp, %esp
popl %ebp
ret
.extern putchar
.align 16
nl:
pushl %ebp
movl %esp, %ebp
pushl $'\n'
call putchar
movl %ebp, %esp
popl %ebp
ret
.text
.align 16
.extern exit
finish:
pushl $0
call exit
.text
_form3: .asciz "%lld"
.align 16
readi64:
pushl %ebp
movl %esp, %ebp
subl $8, %esp
leal -8(%ebp), %eax
pushl %eax
pushl $_form3
call scanf
add $8, %esp
movl %eax, %ecx
movl -8(%ebp), %eax
movl -4(%ebp), %edx
clc
cmpl $1, %ecx
je readi64x
stc
readi64x:
movl %ebp, %esp
popl %ebp
ret
.text
_form4: .asciz "%lld"
.align 16
writei64:
pushl %ebp
movl %esp, %ebp
pushl %edx
pushl %eax
pushl $_form4
call printf
add $12, %esp
movl %ebp, %esp
popl %ebp
ret