我需要编写一个程序来查找正方形区域(浮点十进制),其中所有计算都是通过函数调用完成的。我已经逐步执行了程序并加载到寄存器中$ f0是应该是我需要的结果的值,但是它会保持打印出区域值为1。
为了澄清,该程序的用法如下:
enter x1
enter x2
enter y1
enter y2
计算x中的变化,然后更改y,然后添加它们 广场那个数字(找到距离) 转到函数计算方形区域(r ^ 2)
,代码如下:
# A program to demonstrate function calls
.data # Data declaration section
prompt: .asciiz "\n Please enter an integer "
result1: .asciiz "\n Side 1 is: "
result2: .asciiz "\n Side 2 is: "
result3: .asciiz "\n The distance squared is: "
.double
.text
main: # Start of code section
jal printst
jal readint
mov.d $f2, $f0 #x1
jal printst
jal readint
mov.d $f4, $f0 #x2
jal printst
jal readint
mov.d $f6, $f0 #y1
jal printst
jal readint
mov.d $f8, $f0 #y2
jal square
jal printres
li $v0, 10
syscall
printst:
li $v0, 4
la, $a0, prompt
syscall
jr $ra
readint:
li $v0, 7
syscall
jr $ra
square:
la $s2, getdistance
jalr $s3, $s2
mul.d $f2, $f16, $f16
jr $ra
getdistance:
la $s0, getsides
jalr $s1, $s0
mul.d $f14, $f10, $f10
mul.d $f16, $f12, $f12
add.d $f16, $f16, $f14 #f16 becomes length of side
jr $s3
getsides:
sub.d $f10, $f4, $f2 #(x2-x1)
sub.d $f12, $f8, $f6 #(y2-y1)
jr $s1
printres:
li $v0, 4
la, $a0, result1
syscall
li $v0, 3
mov.d $f0, $f10
syscall
li $v0, 4
la, $a0, result2
syscall
li $v0, 3
mov.d $f0, $f12
syscall
li $v0, 4
la, $a0, result3
syscall
li $v0, 3
mov.d $f0, $f2
syscall
jr $ra
# END OF PROGRAM
哦,而且:我输入的值(最终获得1的结果)是:x1:1 x2:2 y1:1 y2:2