我需要有关如何使用浮点寄存器

时间:2015-10-14 17:39:12

标签: assembly mips

所以我编写了一个mips代码来查找圆柱体的表面区域。我会在这里分享一些......

.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 
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 * pi 半径(半径+高度)

编辑:尝试将所有内容转换为浮动寄存器的新尝试

.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

中的语法错误

1 个答案:

答案 0 :(得分:2)

以下是一个让您入门的示例:

.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

上的值