因此,对于一项分配,我需要创建一个汇编程序,以查找从二进制文件传入的浮点的立方根。似乎一切正常,除了计算结束时有一个无限循环。
calcCR:
stp x29, x30, [sp, -16]!
mov x29, sp
//d0 contains the initial value
fmov d31, d0
//first step is x = input/3.0, this is initial setup and only should be done once, loop starts on step 2
adrp x9, a_m //a_m is 3.0
add x9, x9, :lo12:a_m
ldr d1, [x9] //d1 = 3.0
adrp x10, b_m //b_m is 1.0e-10
add x10, x10, :lo12:b_m
ldr d16, [x10] //d16 = 1.0e-10
fmul d17, d31, d16 //d17 = input*1.0e-10
fdiv d2, d31, d1 //d2 = x
calcTop:
//second step is y = x*x*x
fmul d3, d2, d2
fmul d3, d3, d2 //d3 = y
//third step is dy = y-input
fsub d4, d3, d31 //d4 = dy
//fourth step is dy/dx = 3.0*x*x
ldr d1, [x9]
fmul d5, d1, d2
fmul d5, d5, d2 //d5 = dy/dx
//fifth step is x = x-dy / (dy/dx), this will be the new trial value for x
fsub d6, d2, d4
fdiv d2, d6, d5 //d2 = new trial x
//sixth step is get the absolute value of dy
fabs d7, d4 //d7 = abs dy, using this value causes an infinite loop in the comparison
//seventh step is compare the absolute value of dy to input*1.0e-10
//if |dy| is greater, go back to calcTop, if it is less then we're done, exit loop
fcmp d7, d17 //this comparison and branch is causing the infinite loop.
b.ge calcTop
fmov d0, d2
ldp x29, x30, [sp], 16
ret
关于计算部分分配的说明是:“牛顿法要求对立方根进行初始猜测;使用x =输入/ 3.0。使用y = x * x计算y,即当前猜测x的立方。 * x。然后计算y和输入值之间的差dy:使用dy = y-输入,计算dy / dx = 3.0 * x * x的导数dy / dx,然后使用x =计算x的新试验值。 x-dy /(dy / dx)。重复这些步骤,直到使用公式| dy |
我100%不明白为什么它不能正常工作,因此不胜感激。