Assembly 浮点乘法
我不熟悉MIPS编程,在从用户那里读入两个浮点后,我很难理解如何将它们相乘。如何将参数转换为单精度浮点数?当我运行程序时,它将结果打印为0.0,而不是数字乘以常数。有人能告诉我为什么打印0.0而不是正确的数字吗Assembly 浮点乘法,assembly,floating-point,mips,floating-point-precision,Assembly,Floating Point,Mips,Floating Point Precision,我不熟悉MIPS编程,在从用户那里读入两个浮点后,我很难理解如何将它们相乘。如何将参数转换为单精度浮点数?当我运行程序时,它将结果打印为0.0,而不是数字乘以常数。有人能告诉我为什么打印0.0而不是正确的数字吗 .data prompt: .asciiz "Enter the amount: " newline: .asciiz "\n" float1: .float 0.0 const: .float 121.28 .text .globl main main:
.data
prompt: .asciiz "Enter the amount: "
newline: .asciiz "\n"
float1: .float 0.0
const: .float 121.28
.text
.globl main
main:
li $v0, 4 #calls print_string code 4
la $a0, prompt #pointer to string
syscall
#get amount from user
li $v0, 6 #call read_float code 6
syscall
la $a0, float1 #loads address of float1
l.s $f1, 0($a0) #a0 --> float1
la $a1, const #loads address of const
l.d $f2, 0($a1) #a1 --> float2
#calculates
mul.s $f1, $f1, $f2 #f1 = f1*f2
#prints resulting amount
li $v0, 2 #calls print_float code 2
syscall
#continual loop
li $v0, 4 #calls print_string code 4
la $a0, newline #pointer to string
syscall
j main #jumps to beginning of main
它打印0,因为你乘以了0。。调用输入后,不存储输入(
s.s$f0,float1#存储输入
),然后如果要在mips中打印,则必须说明。。我再次将操作结果存储在float1中(s.s$f1,float1#store multiplied float
),然后用适当的调用打印l.s$f12,float1#print multiplied float
记住为系统调用函数使用正确的寄存器
这是主工作代码
main:
li $v0, 4 #calls print_string code 4
la $a0, prompt #pointer to string
syscall
#get amount from user
li $v0, 6 #call read_float code 6
syscall
s.s $f0, float1 #store the input
la $a0, float1 #loads address of float1
l.s $f1, 0($a0) #a0 --> float1
la $a1, const #loads address of const
l.d $f2, 0($a1) #a1 --> float2
#calculates
mul.s $f1, $f1, $f2 #f1 = f1*f2
s.s $f1, float1 #store multiplied float
#prints resulting amount
li $v0, 2 #calls print_float code 2
l.s $f12, float1 #print multiplied float
syscall
#continual loop
li $v0, 4 #calls print_string code 4
la $a0, newline #pointer to string
syscall
j main
如果您稍微想一想,
read\u float
显然无法神奇地将输入读取到float1
。因此,您是在与零相乘。如果查阅手册,您将看到read\u float
返回$f0
中的值。另外,学习使用调试器。