Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .data
  2. prompt1: .asciiz "Enter your p\n"
  3. prompt2: .asciiz "Enter your q\n"
  4. onesolution: .asciiz "There is the following solution: "
  5. nosolution: .asciiz "There is no solution\n"
  6. twosolutions: .asciiz "The first solution: "
  7. twosolutionstwo: .asciiz "The second solution: "
  8. again: .asciiz "\nType 0 to stop running. Enter any other integer to continue"
  9. leer: .asciiz "\n"
  10. divideby4: .double 4
  11. storezero: .double 0
  12. divideby2: .double 2
  13. storeminus1: .double -1
  14.  
  15. .text
  16. main:
  17.  
  18. loop:
  19. l.d $f18,storeminus1 #18 enthält -1
  20. l.d $f10,divideby4 #f10 enthält 4
  21. l.d $f8,storezero #f8 enthält 0
  22. l.d $f6,divideby2 #f6 enthält 2
  23. la $a0,prompt1 #Asks for P
  24. li $v0,4
  25. syscall
  26.  
  27. li $v0,7
  28. syscall
  29. mov.d $f12,$f0 #f12 stores the P
  30.  
  31. la $a0,prompt2 #Asks for Q
  32. li $v0,4
  33. syscall
  34. li $v0,7
  35. syscall
  36. mov.d $f14,$f0 #f14 stores the Q
  37.  
  38. jal diskriminante
  39. jal equaltozero
  40. jal smallerthanzero
  41. j loop
  42.  
  43. ##############################################################################
  44.  
  45. diskriminante:
  46. mul.d $f2,$f12,$f12  #$f2 enthält jetzt unser D
  47. div.d $f2,$f2,$f10
  48. sub.d $f2,$f2,$f14
  49. jr $ra
  50.  
  51. equaltozero: #checks if the number is 0
  52. c.eq.d $f2,$f8 #this function checks whether its equal as double precision and then puts a flag
  53. bc1t resultzero #checks the prev. set flag
  54. jr $ra
  55.  
  56. smallerthanzero:#checks for whether it needs to jump in the bigger or smaller than 0 part
  57. c.lt.d $f2,$f8
  58. bc1t minusnumber
  59. bc1f plusnumber
  60.  
  61. ############################################################################
  62.  
  63.  
  64. minusnumber: #when the number is <0
  65. la $a0,nosolution
  66. li $v0,4
  67. syscall
  68. j continue
  69.  
  70. ###########################################################################
  71. plusnumber: #when the number is >0
  72. div.d $f12,$f12,$f6     #calculates -p/2 and the root of D
  73. mul.d $f12,$f12,$f18
  74. sqrt.d $f2,$f2
  75. sub.d $f20,$f12,$f2 #saves the result of the subtraction in f20
  76. add.d $f12,$f12,$f2 #saves the result of the addition in f12
  77. la $a0,twosolutions #just the syscalls for printing the msg and the double number
  78. li $v0,4
  79. syscall
  80. li $v0, 3
  81. syscall
  82. la $a0,leer
  83. li $v0,4
  84. syscall
  85. la $a0,twosolutionstwo
  86. li $v0,4
  87. syscall
  88. mov.d $f12,$f20  #Need to move the 2nd solution to f12 to get it outputable
  89. li $v0,3
  90. syscall
  91. j continue
  92.  
  93. ############################################################
  94.  
  95.  
  96.  
  97. resultzero: #When the result of the equotion is 0
  98. la $a0,onesolution
  99. li $v0,4
  100. syscall
  101. div.d $f12,$f12,$f6 #divides the P with 2
  102. mul.d $f12,$f12,$f18 #Multiplies it with -1 to get the -
  103. li $v0,3
  104. syscall
  105. j continue
  106.  
  107. ##########################################Just for looping the previous
  108. continue:
  109. la $a0,again
  110. li $v0,4
  111. syscall
  112. li $v0,5
  113. syscall
  114. beqz $v0,end
  115. j loop
  116.  
  117. end:
  118. li $v0,10
  119. syscall
  120. #########################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement