Question: I am new to assembly language(MIPS) and was trying to make a function that calculates the square root of an integer but couldn’t figure out the logic to it. Can someone help or guide me how to correctly code it out. Thank You.

Answer: 
Below is the code for calculating the square root of an integer using [Newton’s Method](https://en.wikipedia.org/wiki/Newton%27s_method):

```
.globl Squareroot # Function for Squareroot
.ent Squareroot
Squareroot:
#Using Newton’s Method
move $v0, $a0 # $v0 = x = N
li $t6, 0 # counter
Loop:
div $t7, $a0, $v0 # N/x
add $v0, $t7, $v0 # x + N/x
div $v0, $v0, 2 # (x + N/x)/2
add $t6, $t6, 1
blt $t6, 20, Loop
jr $ra
.end Squareroot

```
If you're using a version with support for the coprocessor1 - floating point.

you can use that to perform the sqrt calculation for you.

$f means a valid floating point register.
this could be $f0-f31.

If you want to work with double-precision (which can represent a full 32bit int without losing accuracy)
{on a 32 bit mips arc} you should only use the EVEN register numbers $f0,f2,f4 ... f30

use the instructions: {if you are using floats (single-precision), use word/single version of the command}

* load-doubleword-coprocessor1: [ldc1 $f, base+offset] # {lwc1}
* square-root-double: [sqrt.d $f, $f] # {sqrt.s}
* convert-word-from-double: [cvt.w.d $f, $f] # {cvt.w.s}
* move-from-coprocessor1: [mfc1.d $r, $f] # {mfc1.s}

'# $r means a general register, like $t0-8, $s0-8 ect