MIPS浮点乘法

时间:2015-06-29 23:00:53

标签: 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:   


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

1 个答案:

答案 0 :(得分:0)

打印0'因为你在输入一个你没有存储它的输入(s.s $f0, float1 #store the input)之后乘以0 ..之后如果你想用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