Assembly 我需要关于如何使用浮点寄存器的帮助
所以我写了一个mips代码来求圆柱体的表面积。我将在这里分享其中的一部分 .文本Assembly 我需要关于如何使用浮点寄存器的帮助,assembly,mips,Assembly,Mips,所以我写了一个mips代码来求圆柱体的表面积。我将在这里分享其中的一部分 .文本 main: #Get height li $v0, 4 #Load syscall print la $a0, height syscall #print #Store height li $v0, 6 #read float syscall #make the call move $t0, $v0 #make height $t0 #Get radius li $v0
main:
#Get height
li $v0, 4 #Load syscall print
la $a0, height
syscall #print
#Store height
li $v0, 6 #read float
syscall #make the call
move $t0, $v0 #make height $t0
#Get radius
li $v0, 4 #Load syscall print
la $a0, input2
syscall #print
#Store radius
li $v0, 6 #read float
syscall #make the call
move $t1, $v0 #make radius $t1
li.s $t3, 3.14159265359
li.s $t5, 2.0
#Calculate the surface area
add.s $t4, $t0, $t1
mul.s $s0,$t4, $t1
mul.s $s1, $s0, $t3
mul.s $s2, $t5, $s1
我意识到,就寄存器而言,对于浮点数来说,这是不正确的。我需要一个如何我可以调整这是准确的浮点数手。多谢各位
此外,如果您对数学感兴趣,SA=2*piradius(半径+高度)
编辑:尝试将所有内容转换为浮动寄存器的新尝试
.text
main:
#Get height
li $v0, 4 #Load syscall print
la $a0, height
syscall #print
#Store height
li $v0, 6 #read float
syscall #make the call
mov.s $f0, $v0 #make height $f0
#Get radius
li $v0, 4 #Load syscall print
la $a0, input2
syscall #print
#Store radius
li $v0, 6 #read float
syscall #make the call
mov.s $f1, $v0 #make radius $f1
li.s $f8, 3.14159265359
li.s $f7, 2.0
#Calculate the surface area
add.s $f2, $f0, $f1
mul.s $f3,$f2, $f1
mul.s $f4, $f3, $f8
mul.s $f6, $f7, $f4
我从这里得到的错误是mov.s$f0,$v0中的语法错误这里有一个示例来帮助您开始:
.data
height: .asciiz "Enter height: "
input2: .asciiz "Enter radius: "
pi: .float 3.14159265359
two: .float 2.0
.text
main:
#Get height
li $v0, 4 #Load syscall print
la $a0, height
syscall #print
#Store height
li $v0, 6 #read float
syscall #make the call (input value stored on $f0)
mov.s $f1, $f0
#Get radius
li $v0, 4 #Load syscall print
la $a0, input2
syscall #print
#Store radius
li $v0, 6 #read float
syscall #make the call
mov.s $f2, $f0
l.s $f3, pi
l.s $f5, two
#Calculate the surface area
add.s $f4, $f2, $f1
mul.s $f0, $f3, $f5
mul.s $f0, $f0, $f2
mul.s $f12, $f0, $f4
li $v0, 2 #print float (input expected in $f12)
syscall #make the call
请注意,必须将浮点寄存器与
add.s
/mul.s
指令一起使用。另请注意,syscall
4返回浮点寄存器上的值f0
根据我的google foo,这:显示了如何使用浮点寄存器来完成所需的操作。谷歌搜索“MIPS浮点指令”也给我带来了很多好的点击率。是的,我见过这种情况,但每次我尝试实现时都会遇到问题。特别是从用户处读入数字并将其存储在一个可用的注册表中,您确定读入函数接受浮点数吗?如果不是,则需要从int转换为float,或者找到一个与float一起工作的read函数。或者,你可以使用定点数学,但这可能不是你想去的地方。让我编辑原始文章,尝试使用read-in函数adjustedAh!我们请了一位专家插话。谢谢你,因为我充其量只是一个MIPS黑客:)非常感谢你……最简单的事情是,它存储在$f0和$v0中,这让我很失望,谢谢