Advertisement
Guest User

Untitled

a guest
Jul 16th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. #dev note compute time is more valuable than computer hardware
  2. .data
  3. #useful nmumbers
  4. four: .double 4.0
  5. two: .double 2.0
  6. zero: .double 0.0
  7. #user questions
  8. pq: .asciiz "q > "
  9. qq: .asciiz "p > "
  10. slcnt: .asciiz " solution(s)\n"
  11. solone: .asciiz "\n solution 1: "
  12. soltwo: .asciiz "\n solution 2: "
  13.  
  14. .text
  15. #pq dialog
  16. la $a0, pq
  17. li $v0, 4
  18. syscall
  19. #pa dialog
  20. li $v0, 7
  21. syscall
  22. mov.d $f14, $f0 #move p to reg f14
  23. #qq dialog
  24. la $a0, qq
  25. li $v0, 4
  26. syscall
  27. #qa dialog
  28. li $v0, 7
  29. syscall
  30. mov.d $f12, $f0 #move p to reg f14
  31.  
  32. jal quadsolve
  33.  
  34. ##### output ####
  35.  
  36. add $a0, $zero, $t0 #print solution count
  37. li $v0, 1
  38. syscall
  39.  
  40. li $v0, 4
  41. la $a0, slcnt #print solution count text
  42. syscall
  43.  
  44. beqz $t0, end #when no solution over here
  45.  
  46. #### min 1 solution ####
  47.  
  48. li $v0, 4
  49. la $a0, solone #print solution one text
  50. syscall
  51.  
  52. mov.d $f12, $f0 #load solution one in output register
  53. li $v0, 3
  54. syscall
  55.  
  56. subiu $t0, $t0, 1
  57. beqz $t0, end
  58.  
  59. #### full 2 solutions ####
  60. li $v0, 4
  61. la $a0, soltwo #print solution two text
  62. syscall
  63.  
  64. mov.d $f12, $f2
  65. li $v0, 3
  66. syscall
  67.  
  68. j end # ends programm
  69.  
  70. #q is $f12 - $f13
  71. #p is $f14 - $f15
  72. #D is $f16 - $f17
  73. #-p/2 is $f8-$f9
  74. quadsolve:
  75. #set some helpful values
  76. l.d $f10, zero
  77. l.d $f18, four
  78.  
  79. #calc d
  80. mul.d $f16, $f14, $f14
  81. div.d $f16, $f16, $f18
  82. sub.d $f16, $f16, $f12
  83.  
  84. # -p/2 errechenen
  85. l.d $f18, two #f18 is now 2
  86. sub.d $f8, $f10, $f14
  87. div.d $f8, $f8, $f18
  88.  
  89. #check if d is 0 or smaller
  90. c.lt.d $f16, $f10
  91. bc1t no
  92. c.eq.d $f16, $f10
  93. bc1t single
  94. j double
  95.  
  96. double:
  97. l.d $f18, two #f18 is now 2
  98. sqrt.d $f16, $f18
  99. sub.d $f0, $f8, $f16 #return -p/2 - d in $f0
  100. add.d $f2, $f8, $f16 #return -p/s + d in $f2
  101. li $t0, 2
  102. jr $ra
  103.  
  104. single:
  105. mov.d $f8, $f0 #return -p/2 in $f0
  106. li $t0, 1
  107. jr $ra
  108.  
  109. no:
  110. li $t0, 0 #return nothing in $f0 and $f2
  111. jr $ra
  112.  
  113. end:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement