-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmyprintf.s
More file actions
315 lines (311 loc) · 4.91 KB
/
myprintf.s
File metadata and controls
315 lines (311 loc) · 4.91 KB
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
.file 1 "report2-5.c"
# -G value = 0, Cpu = r2000, ISA = 1
# GNU C version 2.96-mips3264-000710 (mipsel-linux) compiled
# by GNU C version 2.96 20000731 (Red Hat Linux 7.2 2.96-112.7.2).
# [AL 1.1, MM 40] BSD Mips
# options passed: -mno-abicalls -mrnames -mmips-as
# -mno-check-zero-division -mcpu=r2000 -O0 -fleading-underscore
# -finhibit-size-directive -fverbose-asm
# options enabled: -fpeephole -fkeep-static-consts -fpcc-struct-return
# -fsched-interblock -fsched-spec -fnew-exceptions -fcommon
# -finhibit-size-directive -fverbose-asm -fgnu-linker -flive-range-gdb
# -fargument-alias -fleading-underscore -fdelay-postincrement -fident
# -fmath-errno -msplit-addresses -mrnames -mno-check-zero-division
# -mdebugf -mdebugi -mno-div-checks -mcpu=r2000
.text
.align 2
.set nomips16
_print_char:
subu $sp,$sp,40
sw $ra,36($sp)
sw $fp,32($sp)
move $fp,$sp
move $v0,$a0
sb $v0,16($fp)
lbu $v0,16($fp)
sb $v0,24($fp)
sb $zero,25($fp)
addu $v0,$fp,24
move $a0,$v0
jal _print_string
move $sp,$fp
lw $ra,36($sp)
lw $fp,32($sp)
addu $sp,$sp,40
j $ra
.rdata
.align 0
.align 2
$LC0:
.asciiz "0123456789ABCDEF"
.text
.align 2
.set nomips16
_hexadecimal_print:
subu $sp,$sp,48
sw $ra,44($sp)
sw $fp,40($sp)
move $fp,$sp
sw $a0,48($fp)
addu $v0,$fp,16
addu $v1,$fp,16
la $v0,$LC0
lwl $a0,3($v0)
lwr $a0,0($v0)
lwl $a1,7($v0)
lwr $a1,4($v0)
lwl $a2,11($v0)
lwr $a2,8($v0)
lwl $a3,15($v0)
lwr $a3,12($v0)
swl $a0,3($v1)
swr $a0,0($v1)
swl $a1,7($v1)
swr $a1,4($v1)
swl $a2,11($v1)
swr $a2,8($v1)
swl $a3,15($v1)
swr $a3,12($v1)
lb $a0,16($v0)
sb $a0,16($v1)
lw $v0,48($fp)
srl $v0,$v0,4
beq $v0,$zero,$L4
lw $v0,48($fp)
srl $v0,$v0,4
move $a0,$v0
jal _hexadecimal_print
$L4:
lw $v0,48($fp)
andi $v1,$v0,0xf
addu $v0,$fp,16
addu $v0,$v0,$v1
lb $v0,0($v0)
move $a0,$v0
jal _print_char
move $sp,$fp
lw $ra,44($sp)
lw $fp,40($sp)
addu $sp,$sp,48
j $ra
.rdata
.align 0
.align 2
$LC1:
.asciiz "01234567"
.text
.align 2
.set nomips16
_octal_print:
subu $sp,$sp,40
sw $ra,36($sp)
sw $fp,32($sp)
move $fp,$sp
sw $a0,40($fp)
addu $v0,$fp,16
addu $v1,$fp,16
la $v0,$LC1
lwl $a0,3($v0)
lwr $a0,0($v0)
lwl $a1,7($v0)
lwr $a1,4($v0)
lb $a2,8($v0)
swl $a0,3($v1)
swr $a0,0($v1)
swl $a1,7($v1)
swr $a1,4($v1)
sb $a2,8($v1)
lw $v0,40($fp)
srl $v0,$v0,3
beq $v0,$zero,$L6
lw $v0,40($fp)
srl $v0,$v0,3
move $a0,$v0
jal _octal_print
$L6:
lw $v0,40($fp)
andi $v1,$v0,0x7
addu $v0,$fp,16
addu $v0,$v0,$v1
lb $v0,0($v0)
move $a0,$v0
jal _print_char
move $sp,$fp
lw $ra,36($sp)
lw $fp,32($sp)
addu $sp,$sp,40
j $ra
.align 2
.set nomips16
_myprintf:
sw $a0,0($sp)
sw $a1,4($sp)
sw $a2,8($sp)
sw $a3,12($sp)
subu $sp,$sp,32
sw $ra,28($sp)
sw $fp,24($sp)
move $fp,$sp
sw $a0,32($fp)
addu $v0,$fp,32
sw $v0,16($fp)
$L8:
lw $v0,32($fp)
lb $v0,0($v0)
bne $v0,$zero,$L10
b $L9
$L10:
lw $v0,32($fp)
lb $v1,0($v0)
li $v0,37 # 0x25
bne $v1,$v0,$L11
lw $v0,32($fp)
addu $v0,$v0,1
sw $v0,32($fp)
lw $v0,32($fp)
lbu $v0,0($v0)
addu $v0,$v0,-99
sll $v0,$v0,24
sra $v0,$v0,24
sw $v0,20($fp)
lw $v1,20($fp)
sltu $v0,$v1,22
beq $v0,$zero,$L20
lw $v0,20($fp)
sll $v1,$v0,2
la $v0,$L18
addu $v0,$v1,$v0
lw $v0,0($v0)
j $v0
.rdata
.align 0
.align 3
$L18:
.word $L15
.word $L13
.word $L20
.word $L20
.word $L20
.word $L20
.word $L20
.word $L20
.word $L20
.word $L20
.word $L20
.word $L20
.word $L17
.word $L20
.word $L20
.word $L20
.word $L14
.word $L20
.word $L20
.word $L20
.word $L20
.word $L16
.text
$L13:
lw $v0,16($fp)
addu $v0,$v0,4
sw $v0,16($fp)
lw $v0,16($fp)
lw $a0,0($v0)
jal _print_int
b $L20
$L14:
lw $v0,16($fp)
addu $v0,$v0,4
sw $v0,16($fp)
lw $v0,16($fp)
lw $a0,0($v0)
jal _print_string
b $L20
$L15:
lw $v0,16($fp)
addu $v0,$v0,4
sw $v0,16($fp)
lw $v0,16($fp)
lb $v0,0($v0)
move $a0,$v0
jal _print_char
b $L20
$L16:
lw $v0,16($fp)
addu $v0,$v0,4
sw $v0,16($fp)
lw $v0,16($fp)
lw $a0,0($v0)
jal _hexadecimal_print
b $L20
$L17:
lw $v0,16($fp)
addu $v0,$v0,4
sw $v0,16($fp)
lw $v0,16($fp)
lw $a0,0($v0)
jal _octal_print
b $L20
$L11:
lw $v0,32($fp)
lb $v0,0($v0)
move $a0,$v0
jal _print_char
$L20:
lw $v0,32($fp)
addu $v0,$v0,1
sw $v0,32($fp)
b $L8
$L9:
move $sp,$fp
lw $ra,28($sp)
lw $fp,24($sp)
addu $sp,$sp,32
j $ra
.rdata
.align 0
.align 2
$LC2:
.asciiz "ABC"
.align 2
$LC3:
.asciiz "test: %d, %s, %c, %x, %o\n"
.align 2
$LC4:
.asciiz "Done.\n"
.text
.align 2
.set nomips16
main:
subu $sp,$sp,40
sw $ra,36($sp)
sw $fp,32($sp)
move $fp,$sp
addu $v0,$fp,24
addu $v0,$fp,24
la $v0,$LC2
la $v1,$LC2
lbu $v0,0($v1)
sb $v0,24($fp)
lbu $v0,1($v1)
sb $v0,25($fp)
lbu $v0,2($v1)
sb $v0,26($fp)
lbu $v0,3($v1)
sb $v0,27($fp)
li $v0,19 # 0x13
sw $v0,16($sp)
li $v0,10 # 0xa
sw $v0,20($sp)
la $a0,$LC3
li $a1,10 # 0xa
addu $a2,$fp,24
li $a3,97 # 0x61
jal _myprintf
la $a0,$LC4
jal _print_string
move $v0,$zero
move $sp,$fp
lw $ra,36($sp)
lw $fp,32($sp)
addu $sp,$sp,40
j $ra