EXTREMEXPLOIT

SQRT

Dec 22nd, 2020 (edited)
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. .data
  2. n: .word 4
  3.  
  4. .text
  5. .globl sqrt
  6.  
  7. sqrt:
  8.  
  9. la $t0, n # That's the sqrt(n)
  10. lw $t0, ($t0)
  11.  
  12. li $t1, -1 # At the start of the loop, i = 0.
  13.  
  14. la $t2, n # x = n
  15. lw $t2, ($t2)
  16.  
  17. div $t3, $t2, 2 # n/2
  18.  
  19. loop:
  20. addu $t1, $t1, 1# i++
  21. divu $t4, $t0, $t2 # n/x
  22. addu $t4, $t4, $t2 # x + n/x
  23. divu $t4, $t4, 2, # ( (x + n) / x ) / 2
  24. move $t2, $t4 # x = ( (x + n) / x ) / 2
  25.  
  26. blt $t1, $t3, loop # if i < n/2
  27. bge $t1, $t3, end # else
  28.  
  29. end:
  30. addu $v0, $t2, $zero
  31.  
Add Comment
Please, Sign In to add comment