Advertisement
Guest User

Untitled

a guest
Jun 10th, 2019
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. .text
  3.         .globl __start
  4.  
  5. __start:     
  6.  
  7.             # f1 = 0.0
  8.             l.s $f1, zero_float
  9.            
  10.             # Counter for floats with non-biased exp.
  11.             li $t0, 0
  12.  
  13. while:
  14.             # Read float on $f0
  15.             jal read_float
  16.  
  17.             # If $f0 == 0.0, exit
  18.             c.eq.s $f0, $f1
  19.             bc1t exit
  20.  
  21.             # Move the binary directly to s0
  22.             mfc1 $s0, $f0
  23.  
  24.             # Move the exp bits from 30:23 to 6:0
  25.             sll $s0, $s0, 1
  26.             srl $s0, $s0, 24
  27.  
  28.             # unbiased exp = exp - 127
  29.             sub $s0, $s0, 127
  30.            
  31.             # If unbiased exp > 0, then increment counter
  32.             bge $s0, $zero, add_one
  33.            
  34.             # Else jump back to loop
  35.             j while
  36.  
  37. add_one:  
  38.             add $t0, $t0, 1
  39.             j while
  40.      
  41.  
  42. exit:        
  43.             # Print message
  44.             la $a0, message
  45.             jal print_string
  46.  
  47.             # Print counter
  48.             move $a0, $t0
  49.             jal print_int
  50.  
  51.             li $v0, 10
  52.             syscall    
  53.  
  54. #
  55. #         Functions
  56. #
  57.  
  58. # Prints $a0    
  59. print_int:        li $v0, 1
  60.                   syscall
  61.                   jr $ra
  62. # Prints $f12                      
  63. print_float:      li $v0, 2
  64.                   syscall
  65.                   jr $ra
  66.  
  67.  
  68. # Prints $a0              
  69. print_string:     li $v0, 4
  70.                   syscall
  71.                   jr $ra
  72.  
  73.  
  74. # Outputs float in $f0
  75. read_float:     li $v0, 6
  76.                 syscall
  77.                 jr $ra
  78.  
  79. #
  80. #     Data
  81. #
  82. .data      
  83.  
  84.       zero_float: .float 0.0
  85.       message:    .asciiz "Floats with non-biased exponent: "
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement