Floating point Mips单到双浮点透视
我在mips中有这个程序,我不打算把它改成双精度。看起来单精度浮点指令和双精度浮点指令有相同的指令,但不是.s,而是.d。如果有人推荐或帮助,它将对我的帮助很大Floating point Mips单到双浮点透视,floating-point,mips,double-precision,single-precision,Floating Point,Mips,Double Precision,Single Precision,我在mips中有这个程序,我不打算把它改成双精度。看起来单精度浮点指令和双精度浮点指令有相同的指令,但不是.s,而是.d。如果有人推荐或帮助,它将对我的帮助很大 #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; # f
#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
#巴比伦法:巴比伦法是众多近似根的方法之一。
#该方法使用以下C代码:
#浮动x=n;
#浮动y=1;
#浮点数e=0.000001;/*e决定准确度水平*/
#而(x-y>e)
# {
#x=(x+y)/2;
#y=n/x;
# }
数据
StartingStatement:.asciiz“请输入一个您想要查找其平方根的数字:\n”
答案:.asciiz“您的答案是:\n”
NumberofIterations:.asciiz“请输入迭代次数。示例:100\n”
ErrorQ:“请输入一个大于零的数字!”
结束:.asciiz“\n--end--”
Y:.浮点1.0
小值:。浮点0.000001
两个:.float 2.0
文本
格洛博梅因酒店
主要内容:
#打印启动信息
李$v0,4
la$a0,启动状态
系统调用
li$v0,6#将一个6加载到vo中,用于syscall用户输入
系统调用
mov.d$f2,$f0#$f2有值
mov.d$f8,$f2####将浮点转换为整数
cvt.w.d$f8,$f8
mfc1$t1,$f8#转换后的整数存储在t1中
blt$t1,0,error g#如果int小于1,则抛出一个错误
l、 d$f4,Y#将浮动加载到$f4
l、 d$f12,小值#将值加载到f12中
l、 d$f8,两个#将值加载到f8中
j FindSqaureRoot#现在求平方根
FindSqaureRoot:
#$f2#x
#f4#y
#f12#小值
移动d$f14,$f2#n
#而(x-y>e)
# {
#x=(x+y)/2;
#y=n/x;
# }
#返回x;
减法检查:
sub.d$f2、$f2、$f4#x-y
c、 lt.d$f2,$f12#是(x-y)e?
bc1t循环#是:继续循环!
循环:
添加.d$f6、$f2、$f4#x+y
分区d$f2、$f6、$f8#除以2
d类$f4、$f14、$f2#n/x
减法检查
#打印答案!
打印:
移动d$f16,$f2
李$v0,2
系统调用
j端程序
#数字小于0时生成的错误!
错误:
李$v0,4
洛杉矶$a0,错误Q
系统调用
j端程序
结束程序:
li$v0,4#为xvalue打印消息
洛杉矶$a0,结束
系统调用
李$v0,10
系统调用
好的,您知道这些说明有不同的后缀。那么到底是什么问题呢?我将所有指令转换为双精度,但在/Users/jmurphy/Downloads/mips1.asm第41行:0x00400034处的运行时异常:地址未在双字边界0x100ccwell上对齐,如果要用l.d
加载变量,则必须将变量声明为.double
而不是.float
。