1

我是新手,我试图在不使用协处理器的情况下做到这一点。有什么建议么?我真的需要好好完成这个任务!此代码应该在 MIPS 程序集中,其中代码 newtons 方法并包含 ae 点。我一直在组装我的代码,但它从底部掉了下来……不过我不确定这意味着什么。

#Part 1
# (A) 
# g(x) = 0
# x = 7^(1/3)
# g(x) = x^3 - 7
# g'(x) = 3x^2
.data
x: .float 1.0
bb: .float 7.0
c: .float 3.0
epsilom: .float 0.00001
divide: .float 2.0

#=======================================
# (B)
# Write a MIPS function newtons_top that takes 1 “floating-point argument”: 
# $f0   xn, the current estimate of the root 
# It computes your function g(xn) = g($f0), and leaves the result in $f2.  Do not 
# modify $f0’s value.  (This would be a good place to document your g(x).)
newtons_top:
l.s $f0, x
l.s $f1, bb
mul.s $f5, $f0, $f0
mul.s $f0, $f5, $f0
sub.s $f2, $f0, $f1

#=======================================
# (C)
# $f0   xn, the current estimate of the root 
# It computes your function g’(xn) = g’($f0), and leaves the result in $f4.  Do not 
# modify $f0’s value.  (This would be a good place to document your g’(x).)
newtons_bottom:
l.s $f3, c
mul.s $f5, $f0, $f0
mul.s $f4, $f5, $f3


#======================================
#(D)
#  Write a MIPS function newtons_err that takes 1 “floating-point argument”: 
# $f0   xn, the current estimate of the root 
# It computes the error term ?n from (Eq. 3), and leaves the result in $f6.  Do not 
# modify $f0’s value.  Hint: Call your previous function
newtons_err:
div.s $f6,$f2,$f4


#========================================
#(E)

newtons_nth:
div.s $f2, $f0, $f1  # $f2 gets n/x
add.s $f2, $f2, $f1  # $f2 gets n/x + x
div.s $f2, $f2, divide  # $f2 gets x'=(n/x + x)/2
sub.s $f3, $f2, $f1  # $f3 gets x'-x
abs.s $f3, $f3       # $f3 gets |x'-x|
c.lt.s $f3, epsilom     # set the flag if |x'-x| < 0.00001
li $v0, 1


#===========================================
#(F)
#  Write a MIPS function newtons_gee that takes no arguments, and does this: 
#• Initializes x0 = 1.0 from (Eq. 1), by setting $f0 to 1.0. 
# • Repeatedly calls newtons_nth until the return value is non-zero. 
# Remember to pass the current  n in $a0 (even if your implementation 
# doesn’t use it for printing)

newtons_gee:
l.s $f0, 1
beqz $t3, newtons_nth

#=============================================
# Main Block

main:
j newtons_gee
syscall 
4

1 回答 1

3

这是一个开始。

下面的代码是废话:

newtons_gee:
    l.s $f0, 1
    beqz $t3, newtons_nth

要在 MIPS 汇编中调用函数,您应该使用jal指令而不是beqz. 跳转到$t3时具有未定义的值(可能非零),因此不采用分支并且控制返回到。mainnewtons_geemain

您需要返回并重新阅读有关如何进行函数调用的笔记。

于 2011-11-10T19:07:49.543 回答