Sir, can you please make quadratic equation solver in assembly or just
square root function I’m having a problem in square root part please
help?
Raj
2016-03-25 08:14
See below:
#——————————————————————————————
# Subroutine: sqrt
# Usage: v0 = sqrt(a0)
# Description:
# Takes a positive signed integer in $a0 and returns its integer square root
# (i.e., the floor of its real square root) in $v0.
# Arguments: $a0 – A positive signed integer to take the square root of.
# Result: $v0 – The floor of the square root of the argument, as an integer.
# Side effects: The previous contents of register $t0 are trashed.
# Local variables:
# $v0 – Number r currently being tested to see if it is the square root.
# $t0 – Square of r.
# Stack usage: none
#——————————————————————————————
sqrt: addi $v0, $zero, 0 # r := 0
loop: mul $t0, $v0, $v0 # t0 := r*r
bgt $t0, $a0, end # if (r*r > n) goto end
addi $v0, $v0, 1 # r := r + 1
j loop # goto loop
end: addi $v0, $v0, -1 # r := r – 1
jr $ra # return with r-1 in $v0
-Amell