Guest User

Untitled

a guest
Feb 21st, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.31 KB | None | 0 0
  1. .data
  2. msg1: .asciiz "Please enter the degree of Polynomial:"
  3. msg2: .asciiz "Please enter left bound."
  4. msg3: .asciiz "Please enter right bound."
  5. msg4: .asciiz " Please enter coefficient until N-1 is complete."
  6. offset: .float .0001 #where the bounds are going to be stored
  7. .text
  8.  
  9. Main:
  10. li $v0,4
  11. la $a0, msg1
  12. syscall
  13. li $v0, 5
  14. syscall
  15. move $a0,$v0
  16. li $v0,1
  17. syscall #checks print degree
  18. move $s1,$a0 #-------------------------------$s1 holds degree for entire project
  19.  
  20. li $v0,4
  21. la $a0, msg2
  22. syscall
  23. li $v0, 5
  24. syscall
  25. move $a0,$v0
  26. li $v0,1
  27. syscall #checks print left bound
  28. move $s0,$a0 #--------------------------------$s0 holds left bound
  29.  
  30.  
  31. li $v0,4
  32. la $a0, msg3
  33. syscall
  34. li $v0, 5
  35. syscall
  36. move $a0,$v0
  37. li $v0,1
  38. syscall #checks print right bound
  39. move $s2,$a0 #---------------------------------$s2 holds right bound
  40.  
  41. #Allocate memory in the stack
  42. li $s3, 4 #size of integer 4 bytes
  43. mul $s3, $s3, $s1 #compute the size of the array of coefficients
  44. addi $s3, $s3, 12 #create 2 more additional places in memory
  45. sub $sp, $sp, $s3 #make room on stack for coefficients
  46. sw $ra, 0($sp)
  47. sw $s4, 4($sp)
  48. j Fillcoef
  49.  
  50. Fillcoef:
  51. # This for loop will be called from main and fill and array of coefficients
  52. slt $t2,$t0,$s1
  53. beq $t2,$zero,start
  54. li $v0,4
  55. la $a0, msg4
  56. syscall
  57. li $f0,6
  58. syscall
  59. s.s $f0, 4($sp)
  60. move $t2,$f0 #move user input into temp register
  61. sw $t2,8($sp) #store the coefficient
  62. addi $sp, $sp, 4 #increment stack pointer
  63. addi $t0,$t0,1 #increment counter
  64. b Fillcoef
  65.  
  66. start:
  67. # This will compute the slope and out the coordinates of the minimum
  68. addi $t0, $zero, -1
  69. sw $t0, 4($sp)
  70. lwc1 $f0, 4($sp) # This is dydx or derivative
  71. cvt.s.w $f0, $f0 # convert from float precision
  72. add $t0, $zero, $s0 #add left bound limit to stack
  73. sw $t0, 4($sp)
  74. lwc1 $f1, 4($sp)
  75. cvt.s.w $f1,$f1 # x0 will start at the left bound limit
  76.  
  77. computeSlope:
  78. add $t0,$zero,$zero
  79. sw $t0, 4($sp)
  80. lwc1 $f31,4($sp)
  81. cvt.s.w $f31,$f31 # set $f31 to zero
  82. c.lt.s $f0, $f31 # Check to see if slope is negative
  83. bc1f end # continue loop if slope is negative
  84. jal doEquation # find y value
  85. add $t0, $zero, $v0
  86. sw $t0, 4($sp)
  87. lwc1 $f3, 4($sp)
  88. cvt.s.w $f3,$f3
  89. l.s $f30,offset
  90. sub.s $f4, $f1,$f30 # xOne X0 - .0001
  91. add.s $f5, $f1, $f30 # xTwo x0 + .0001
  92. jal doEquation # find yOne using xOne as x0
  93. add $t0, $zero, $v0
  94. sw $t0, 4($sp)
  95. lwc1 $f6, 4($sp)
  96. cvt.s.w $f6,$f6
  97. jal doEquation # find yTwo using xTwo as x0
  98. add $t0, $zero, $v0
  99. sw $t0, 4($sp)
  100. lwc1 $f7, 4($sp)
  101. cvt.s.w $f7,$f7
  102.  
  103. # calculate derivative yTwo-Yone/x2-x1
  104. sub.d $f6, $f7, $f6
  105. sub.d $f4, $f5, $f4
  106. div.d $f0, $f6, $f4 #derivative has changed
  107. # solve for x where x = x0 - y value/dydx
  108. div.d $f4, $f3, $f0
  109. # make x0 = x
  110. mov.s $f1, $f4
  111. b computeSlope
  112. doEquation:
  113. xor $v0, $v0, $v0 # set $vo to zero
  114.  
  115.  
  116.  
  117. resetSP:
  118. #sub &sp, &sp, $s1 #move the stack pointer to the beginging of the array
  119. end:
  120. #print out the coordinates
  121. jal doEquation #find last y-coordinate
  122. add $t0, $zero, $v0
  123. sw $t0, 4($sp)
  124. lwc1 $f4, 4($sp)
  125. cvt.s.w $f4,$f4
  126. #Print out "the coordinates are ($f1, $f4)"
  127. lw $ra, 0($sp) #restore $ra
  128. lw $s4, 4($sp)
  129. addi $sp, $sp, 4 #shrink stack
  130. jr $ra
Add Comment
Please, Sign In to add comment