Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .data
- n: .word 4
- .text
- .globl sqrt
- sqrt:
- la $t0, n # That's the sqrt(n)
- lw $t0, ($t0)
- li $t1, -1 # At the start of the loop, i = 0.
- la $t2, n # x = n
- lw $t2, ($t2)
- div $t3, $t2, 2 # n/2
- loop:
- addu $t1, $t1, 1# i++
- divu $t4, $t0, $t2 # n/x
- addu $t4, $t4, $t2 # x + n/x
- divu $t4, $t4, 2, # ( (x + n) / x ) / 2
- move $t2, $t4 # x = ( (x + n) / x ) / 2
- blt $t1, $t3, loop # if i < n/2
- bge $t1, $t3, end # else
- end:
- addu $v0, $t2, $zero
Add Comment
Please, Sign In to add comment