.data __buffer: .space 200 __format1: .asciiz "F1: %d%% of all %ss like the %c letter\n" __format2: .asciiz "F2: %d signed = %u unsigned = %bb binary\n" __format3: .asciiz "F3: %bb = %d\n" __str: .asciiz "American" __chrs: .byte 'A', 'B' __int: .word -28 __float: .float 1.2e25 # 1.00111101101000110010101b 2^(83) .float 1048576.0625 # 1.0b 2^(20) .float 1048576.125 # 1.00000000000000000000001b 2^(20) .float 1048576.5 # 1.000000000000000000001b 2^(20) .float 0.5078125 # 1.000001b 2^(-1) .float -0.03125 # -1.0b 2^(-5) .float +1.125 # 1.001b 2^(0) .float -1.25 # -1.01b 2^(0) .float -1.5 # -1.1b 2^(0) .float -1.0 # -1.0b 2^(0) .word 0x00100000 # denorm .word 0x80000000 # -0 .word 0x7f800000 # Inf .word 0xffff0000 # -NaN .text main: move $s1, $ra # leave space in the stack for the parameters addi $sp, $sp, -20 # build sprintf()'s parameters in the stack la $a0, __buffer sw $a0, 0($sp) # 0($sp): __buffer la $a1, __format1 sw $a1, 4($sp) # 4($sp): __format1 addi $a2, $0, 87 sw $a2, 8($sp) # 8($sp): 87 (%d) la $a3, __str sw $a3, 12($sp) # 12($sp): __str (%s) la $t0, __chrs lbu $t0, 1($t0) sw $t0, 16($sp) # 16($sp): __chrs[1] (%c) # sprintf (char *str, const char *format, ...); jal sprintf # print the new string la $a0,__buffer # Print the prompt jal puts la $a0, __buffer sw $a0, 0($sp) # 0($sp): __buffer la $a1, __format2 sw $a1, 4($sp) # 4($sp): __format2 la $t0, __int lw $a2, 0($t0) sw $a2, 8($sp) # 8($sp): __int (%d) move $a3, $a2 sw $a3, 12($sp) # 12($sp): __int (%u) move $t0, $a2 sw $t0, 16($sp) # 16($sp): __int (%b) # sprintf (char *str, const char *format, ...); jal sprintf # print the new string la $a0,__buffer # Print the prompt jal puts la $a0, __buffer sw $a0, 0($sp) # 0($sp): __buffer la $a1, __format3 sw $a1, 4($sp) # 4($sp): __format3 la $t0, __float lw $a2, 0($t0) sw $a2, 8($sp) # 8($sp): __float (%b) move $a3, $a2 sw $a3, 12($sp) # 12($sp): __float (%d) move $t0, $a2 # sprintf (char *str, const char *format, ...); jal sprintf addi $s0, $v0, 0 # print the new string la $a0,__buffer # Print the prompt jal puts # print the number of characters in the last string add $a0, $s0, $0 jal __putint addi $a0, $0, 0x0A jal putc # restore the stack addi $sp, $sp, 20 jr $s1 __putint: # prolog addi $sp, $sp, -8 sw $ra, 0($sp) # body rem $t0, $a0, 10 addi $t0, $t0, '0' div $a0, $a0, 10 beqz $a0, __onedig sw $t0, 4($sp) jal __putint lw $t0, 4($sp) __onedig: add $a0, $0, $t0 jal putc # epilog lw $ra, 0($sp) addi $sp, $sp, 8 jr $ra