
MIPS SQRT using Babylonian method
.data
accuracy: .double 0.000001
starting: .double 1.0
DivideByTwo: .double 2.0
Zero: .double 0.0
.text
main:
l.d $f2,starting # load starting end point
l.d $f8,accuracy # load the accuracy constant into $f8:$f9
l.d $f16,DivideByTwo
li $v0, 7 # service 7 is read double it stores the read double in $f0:$f1
syscall #execute syscall
mov.d $f10,$f0 #save original value
nop
#check if input is less then zero and end if true
l.d $f4,Zero
c.lt.d $f0,$f4
bc1f whileLoop
j EndMe
whileLoop:
sub.d $f6,$f0,$f2 #subtract the input double eg $f0:$f1 - $f2:$f3 or input - y
c.lt.d $f8,$f6 # 0.000001 < (input-y)
nop
bc1f EndLoop #if true then end the loop
nop
add.d $f0,$f0,$f2 # x = (x + y)
div.d $f0,$f0,$f16 # x = x/2
div.d $f2,$f10,$f0 # y= orginal/x
jal PrintArea #print x and y
nop
b whileLoop #branch back to top of while loop
EndLoop:
jal PrintArea
nop
li $v0,10 #exit syscall
syscall
j EndMe
PrintArea:
li $a0,0xA0 # load new line char into $a0
li $v0,3
mov.d $f12,$f0 #print x
syscall
li $v0,11 #print new line char
syscall
mov.d $f12,$f2 #print y
syscall
li $v0,11 #print new line char
syscall
jr $ra
EndMe:
Leave MIPS SQRT using Babylonian method to:
Read more #mips posts
Best Posts From Noah the Goodra
We have not curated any of jfmherokiller's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.
More Posts From Noah the Goodra
- how to use vtnetcore in a commandline app
- how to access the firebase database emulator from the .net implementation of the realtime database
- tips for deserializing json using newtonsoft.json
- a tip for programming when dealing with databases
- A way to extract strings from the body of a method in c#
- a helpful template for cmake if you are trying to upgrade a project which uses autoconf
- A method of fixing the fps issues in deadly premonition 2
- how the money value is stored in deadly premonition 2
- I implmented gmcp and mdsp support in protomuck
- A short list of gripes I have with lua as a language
- a script for mudlet to setup channel specific chat modes
- rpcs3 cheats for infamous
- how to modify an object in a table in inform 7
- deploying to github releases from travisci-windows
- clang on windows (installed via scoop) is unable to find headers (a copy from stackoverflow I wrote myself but can still be helpful)
- the beginings of adding libchdr to pcsx2
- A method of making the satisfactory mod manager work with steam
- how to get audio working for a wsl2 client using pulse audio on windows
- a possible way of making your browser work while also running pso2
- a method of getting ttyd working on windows.