0

I have this program in mips and I wasn't to change it to double precision. It looks like single and double precision floating instructions have the same instructions but instead of .s it is .d If anyone has commens or help it would help my out a lot.

#‎Babylonian method: The babylonian method is one of the many method to approximate Roots.
#The method uses the following C code:
#   float x = n;
#   float y = 1;
#   float e = 0.000001; /* e decides the accuracy level*/
#   while(x - y > e)
#   {
#     x = (x + y)/2;
#     y = n/x;
#   }

.data
StartingStatment:   .asciiz    "Please enter a number that you would like to find the square root of: \n"
Answer:     .asciiz    "Your answer is: \n"
NumberofIterations: .asciiz "Please enter the number of Iteration. Example: 100\n"
ErrorQ: .asciiz "Pleae enter a number which is greater than zero!"
Ended: .asciiz "\n--Ended--"
Y: .float 1.0
SmallValue: .float 0.000001
Two:        .float 2.0


.text
.globl  main
main:

#printing message for StartingStatment
li  $v0, 4
la  $a0, StartingStatment       
syscall 

li  $v0, 6      #load a six into vo for syscall user input  
syscall         
mov.d $f2, $f0      #$f2 have value
mov.d $f8, $f2      ##### convert float to int
cvt.w.d $f8, $f8
mfc1 $t1, $f8       #converted int stored in t1

blt $t1,0,ErrorG    #if int is less than one then throw an error

l.d $f4, Y      #loading float into $f4
l.d $f12, SmallValue    #load value into f12
l.d $f8, Two        #load value into f8

j FindSqaureRoot    #now find the square root 

FindSqaureRoot:

#$f2        #x
#f4     #y 
#f12        #SmallValue
mov.d $f14,$f2 #n

#while(x - y > e)
#  {
#    x = (x + y)/2;
#    y = n/x;
#  }
#  return x;

SubtractionChecking:
sub.d $f2,$f2,$f4               #x-y

c.lt.d  $f2,$f12                # is (x-y) < e?
bc1t    Print                   #yes:  print(Move towards answer)

c.lt.d  $f12,$f2                # is (x-y) > e?
bc1t    Loop                    # yes: Continue with the #loop!


Loop:
add.d $f6,$f2,$f4               #x+y
div.d $f2,$f6,$f8               #divding it by 2
div.d $f4,$f14,$f2              #n/x
j SubtractionChecking

#Printing the answer!
Print:
mov.d $f16,$f2
li $v0,2
syscall

j EndProgram

#Error that is generated when a number is less than 0!
ErrorG:
li  $v0, 4
la  $a0, ErrorQ     
syscall

j EndProgram

EndProgram:
    li  $v0, 4          # printing message for xvalue
    la  $a0, Ended      
    syscall     

    li $v0,10
    syscall
jmurphy1267
  • 65
  • 1
  • 9
  • Ok, you know that the instructions have a different suffix. So what is the problem exactly? – Michael Apr 08 '15 at 08:34
  • I converted all instructions to the double precision but getting this error Error in /Users/jmurphy/Downloads/mips1.asm line 41: Runtime exception at 0x00400034: address not aligned on doubleword boundary 0x100100cc – jmurphy1267 Apr 08 '15 at 12:47
  • 1
    Well, you have to declare your variables as `.double` instead of `.float` if you're going to load them with `l.d`. – Michael Apr 08 '15 at 12:55

0 Answers0