[英]MIPS Floating Point Multiplication
我是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
它打印0,因為您乘以0。在調用輸入后,您不存儲它( ss $f0, float1 #store the input
),之后,如果要打印在mips中,您必須說什么。我再次將運算結果存儲在float1中( ss $f1, float1 #store multiplied float
),然后打印出正確的調用ls $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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.