diff options
-rw-r--r-- | lib.s | 145 | ||||
-rw-r--r-- | printf.c | 4 |
2 files changed, 66 insertions, 83 deletions
@@ -1,149 +1,132 @@ _func_printf: addiu $sp, $sp, -64 sw $31, 60($sp) #printf -# load fmt_0 +# load pos_0 # load arg_0 # load ch_0 lb $8, 12($sp) #ch +# load fmt_0 + lw $9, 64($sp) #fmt # load x_0 - lw $9, 4($sp) #x + lw $10, 4($sp) #x # load len_0 - lw $10, 8($sp) #len -# t0 = addr fmt_0 - addiu $11, $sp, 64 -# arg_1 = t0 + 4 - addiu $11, $11, 4 + lw $11, 8($sp) #len +# arg_1 = addr pos_0 + addiu $12, $sp, 68 # goto __L2 j __L2 __L1: -# t3 = ch_2 == 37 +# t2 = ch_2 == 37 li $3, 37 - seq $12, $8, $3 -# if not (t3) goto __L20 - beqz $12, __L20 + seq $13, $8, $3 +# if not (t2) goto __L20 + beqz $13, __L20 # fmt_4 = fmt_1 + 1 - lw $2, 64($sp) #fmt - addiu $2, $2, 1 - sw $2, 64($sp) #fmt + addiu $9, $9, 1 # ch_4 = fmt_4[0] - lw $2, 64($sp) #fmt - lb $8, 0($2) -# t5 = ch_4 == 100 + lb $8, 0($9) +# t4 = ch_4 == 100 li $3, 100 - seq $12, $8, $3 -# if not (t5) goto __L6 - beqz $12, __L6 -# t7 = arg_2[0] - lw $12, 0($11) -# push t7 - sw $12, 0($sp) # push -# t6 = call __print_int - jal _func___print_int + seq $13, $8, $3 +# if not (t4) goto __L6 + beqz $13, __L6 +# t6 = arg_2[0] + lw $a0, 0($12) + li $2, 1 + syscall # goto __L19 j __L19 __L6: -# t8 = ch_4 == 99 +# t7 = ch_4 == 99 li $3, 99 - seq $12, $8, $3 -# if not (t8) goto __L8 - beqz $12, __L8 -# t10 = arg_2[0] - lw $12, 0($11) -# push t10 - sw $12, 0($sp) # push -# t9 = call __print_char - jal _func___print_char + seq $13, $8, $3 +# if not (t7) goto __L8 + beqz $13, __L8 +# t9 = arg_2[0] + lw $a0, 0($12) + li $2, 11 + syscall # goto __L19 j __L19 __L8: -# t11 = ch_4 == 115 +# t10 = ch_4 == 115 li $3, 115 - seq $12, $8, $3 -# if not (t11) goto __L10 - beqz $12, __L10 -# t13 = arg_2[0] - lw $12, 0($11) -# push t13 - sw $12, 0($sp) # push -# t12 = call __print_string - jal _func___print_string + seq $13, $8, $3 +# if not (t10) goto __L10 + beqz $13, __L10 +# t12 = arg_2[0] + lw $a0, 0($12) + li $2, 4 + syscall # goto __L19 j __L19 __L10: # x_4 = arg_2[0] - lw $9, 0($11) -# t15 = x_4 == 0 + lw $10, 0($12) +# t14 = x_4 == 0 li $3, 0 - seq $10, $9, $3 -# if not (t15) goto __L12 - beqz $10, __L12 + seq $11, $10, $3 +# if not (t14) goto __L12 + beqz $11, __L12 # len_11 = 1 li $2, 1 - move $10 $2 + move $11 $2 # goto __L15 j __L15 __L12: # len_8 = 0 li $2, 0 - move $10 $2 + move $11 $2 # goto __L14 j __L14 __L13: # x_7 = x_6 / 10 li $3, 10 - divu $9, $9, $3 + divu $10, $10, $3 # len_10 = len_9 + 1 - addiu $10, $10, 1 + addiu $11, $11, 1 __L14: # if (x_6) goto __L13 - bnez $9, __L13 + bnez $10, __L13 __L15: # len_5 = 4 - len_4 li $2, 4 - subu $10, $2, $10 + subu $11, $2, $11 # goto __L17 j __L17 __L16: # push 48 - li $2, 48 - sw $2, 0($sp) # push -# t17 = call __print_char - jal _func___print_char + li $a0 48 + li $2, 11 + syscall # len_7 = len_6 - 1 li $3, 1 - subu $10, $10, $3 + subu $11, $11, $3 __L17: # if (len_6) goto __L16 - bnez $10, __L16 -# t19 = arg_2[0] - lw $12, 0($11) -# push t19 - sw $12, 0($sp) # push -# t18 = call __print_int - jal _func___print_int + bnez $11, __L16 +# t18 = arg_2[0] + lw $a0, 0($12) + li $2, 1 + syscall # fmt_6 = fmt_4 + 2 - lw $2, 64($sp) #fmt - addiu $2, $2, 2 - sw $2, 64($sp) #fmt + addiu $9, $9, 2 __L19: # arg_4 = arg_2 + 4 - addiu $11, $11, 4 + addiu $12, $12, 4 # goto __L21 j __L21 __L20: # push ch_2 - sw $8, 0($sp) # push -# t20 = call __print_char - jal _func___print_char + move $a0, $8 + li $2, 11 + syscall __L21: # fmt_3 = fmt_2 + 1 - lw $2, 64($sp) #fmt - addiu $2, $2, 1 - sw $2, 64($sp) #fmt + addiu $9, $9, 1 __L2: # ch_2 = fmt_1[0] - lw $2, 64($sp) #fmt - lb $8, 0($2) + lb $8, 0($9) # if (ch_2) goto __L1 bnez $8, __L1 _ret_printf: @@ -1,7 +1,7 @@ -int printf(char *fmt) { +int printf(char *fmt, int pos) { char *arg, ch; int len, x; - arg = (int)&fmt + sizeof(char*); + arg = (int)&pos; while ((ch = *fmt)) { if (ch == '%') |