Guest User

Untitled

a guest
Dec 2nd, 2010
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.42 KB | None | 0 0
  1. .data
  2. newline: .ascii "\n"
  3. Input_Message: .asciiz "\nPlease Enter a floating-point number: "
  4. Second_Input_Message: .asciiz "\nPlease enter a second floating-point number: "
  5. Answer: .asciiz "The sum of the two floating point values is: "
  6. .text
  7.  
  8. main:
  9.  
  10. li $v0, 4
  11. la $a0,Input_Message
  12. syscall #syscall to print out the input message
  13.  
  14. li $v0,6
  15. syscall #syscall to read a float input from the user
  16. mfc1 $t0,$f0 #moves the float value from coprocessor to register
  17. add $a1, $t0, $zero #stores the float value into register $a1
  18.  
  19. li $v0, 4
  20. la $a0,Second_Input_Message
  21. syscall #syscall to print out the second input message
  22.  
  23. li $v0,6
  24. syscall # reads a float value from the user
  25. mfc1 $t1,$f0 #moves the float value from coprocessor to register
  26. add $a2, $t1, $zero #stores that value into $a2
  27.  
  28.  
  29. bgtz $a1,exponent #if $a1 is greater than zero, branch to exponent
  30. bgtz $a2,exponent #if $a2 is greater than zero, branch to exponent
  31.  
  32. exponent:
  33.  
  34. move $s0,$a1 #loads $a1 into $s0
  35.  
  36. sll $s5,$s0,1 #shifts $s0 to the left by 1 and store into register $s5
  37.  
  38. srl $s5,$s5,24 #shift $s5 right by 24 and store into $s5
  39.  
  40. move $s1,$a2 #moves the second exponent into register $s1
  41.  
  42. sll $s6,$s1,1 #shifts $s1 left 1 and store into register $s6
  43.  
  44. srl $s6,$s6,24 #shifts $s6 right 24 and store into same register
  45.  
  46.  
  47. srl $s3,$s0,31 #shift $s0 right 31 and store in $s3
  48.  
  49. srl $s4,$s1,31 #shift value $s1 right 31 and store in $s4
  50.  
  51. li $t9,1
  52. sll $t9,$t9,23 #shifts $t9 register left 23
  53.  
  54. sll $s7,$s0,9 #shift $s0 left 9 and store value into $s7
  55. srl $s7,$s7,9 #shift $s7 right 9 and store into $s7
  56. or $s7,$s7,$t9
  57.  
  58.  
  59. sll $t8,$s1,9
  60. srl $t8,$t8,9
  61. or $t8,$t8,$t9
  62.  
  63. Matching_Exponents: #loop which shifts the smaller exponent until it is the same as the larger exponent
  64.  
  65. beq $s5,$s6, Calculations #if the exponents are equal, branch to Calculations
  66. blt $s5,$s6, shift_value_right #continue shifting until exponents are equal
  67. blt $s6,$s5, shift_secondvalue_right #continue shifting until exponents are equal
  68. j Matching_Exponents #loop until conditions are met to branch
  69.  
  70.  
  71.  
  72. shift_value_right: #shifts the value right by 1 and loops until the exponents of the two values match
  73. srl $s7,$s7,1
  74. addi $s5,$s5,1
  75. j Matching_Exponents
  76.  
  77. shift_secondvalue_right: #shifts the value right by 1 and loops until the exponents of the two values match
  78.  
  79. srl $t8,$t8,1
  80. addi $s6,$s6,1
  81. j Matching_Exponents
  82.  
  83. Calculations:
  84. beqz $s3,calc_one #if significand = 0 then branch
  85. sub $s7,$0,$s7
  86.  
  87. calc_one:
  88. beqz $s4,calc_two #if second significand = 0 branch
  89. sub $t8,$0,$t8
  90.  
  91. calc_two:
  92. add $t3,$s7,$t8
  93. li $s3,0
  94. bgez $t3, calc_three
  95. sub $t3,$0,$t3
  96. li $s3,1
  97.  
  98. calc_three:
  99. clz $t2,$t3 #stores the number of leading zeros into $t
  100. blt $t2,8,Branch
  101. bgt $t2,8,Branch_Two
  102. j Normalize #loop
  103. Branch:
  104. srl $t3,$t3,1
  105. addi $s6,$s6,1
  106. j Normalize #loop
  107.  
  108. Branch_Two:
  109. addi $t2,$t2,-8 #adds -8 to $t2
  110. sub $s6,$s6,$t2
  111. sllv $t3,$t3,$t2
  112.  
  113.  
  114. Normalize:
  115. xor $t3,$t3,$t9
  116.  
  117.  
  118. sll $t4,$s3,31 #shift s3 left 31 and store in $t4
  119. sll $t5,$s6,23 #shift s6 left 23 and store in $t5
  120. add $t6,$t4,$t5 #add the value of $t5 and $t6 and store in $t6
  121. add $t6,$t6,$t3 #add $t3 and $t6 and store in $t6
  122.  
  123.  
  124. li $v0, 4 #Prints the prompt defined in the data section Answer:
  125. la $a0,Answer
  126. syscall
  127.  
  128. li $v0,2
  129. mtc1 $t6,$f12 #moves the register value $t6 into coprocessor $f10
  130. syscall
  131.  
  132. exit:
Advertisement
Add Comment
Please, Sign In to add comment