.globl main

.data
prompt:	.asciiz "x= "
result:	.asciiz "y= "
error:	.asciiz "The Square root of negative numbers is not a real number..."
nl:	.asciiz "\n"
two:	.float 2.0
min:	.float 1.0e-5

.text
main:	la $a0, prompt
	li $v0, 4		#print_string the prompt
	syscall
	li $v0, 6		#read_float and enter the value of x
	syscall		#$f0 holds the value of x
	mtc1 $zero, $f1	#load the value of zero in register $f1
	c.lt.s $f0, $f1	#check whether the value entered is negative
	bc1f noerror	#if the value emtered is negative print error message end exit
	la $a0, error
	li $v0, 4		#print_string the error message
	syscall
	la $a0, nl
	li $v0, 4		#print_string new line
	syscall
	jr $ra		#return to the Operating System
noerror:	mov.s $f12, $f0	#$f12 holds the value of y
	la $a0, two
	l.s $f2, ($a0)	#$f2 holds the value of 2.0
	la $a0, min
	l.s $f3, ($a0)	#$f3 holds the value of 0.00001
	j while
body:	div.s $f1, $f0, $f12		#calculate x/y
	add.s $f1, $f1, $f12	#calculate y+x/y
	div.s $f12, $f1, $f2		#calculate (y+x/y)/2 and store the resylt in y
while:	mul.s $f1, $f12, $f12 	#calculate y*y
	sub.s $f1, $f0, $f1		#calculate x-y*y
	abs.s $f1, $f1		#find fabs(x-y*y)
	c.le.s $f1, $f3	#check whether fabs(x-y*y)>0.00001 is true or false
	bc1f body	#go back to condition if the boolean expresion is true
	la $a0, result
	li $v0, 4		#print_string and thell the user the next number is the result
	syscall
	li $v0, 2		#print_float the result
	syscall
	la $a0, nl
	li $v0, 4		#print_string new line
	syscall
	jr $ra		#return control to the Operating System