需要给定正向订单代码的反向订单代码

发布于 2025-01-16 23:05:03 字数 3579 浏览 1 评论 0原文

我需要使用以相反顺序添加的 Nilakantha 级数的前 k 项来计算 pi(单精度)的值。我有远期订单的代码,如下所示。现在有人可以帮助我开始如何进行相反的顺序吗?

    li $t1, 0           # constant value of 0
    mtc1 $t1, $f0       # $f0 = current sum
    cvt.s.w $f0, $f0    # convert representation from 2's complement to IEEE float (not needed for 0)

    li $t1, 2           
    mtc1 $t1, $f2       # $f2 = constant value of 2
    cvt.s.w $f2, $f2    # convert representation of 2 to float

    li $t1, 3           
    mtc1 $t1, $f4       # $f6 = constant value of 3
    cvt.s.w $f4, $f4    # convert representation of 3 to float

    li $t1, 4           
    mtc1 $t1, $f6       # $f6 = constant value of 4
    cvt.s.w $f6, $f6    # convert representation of 4 to float

    li $t1, 0           
    mtc1 $t1, $f8       # $f8 = current numerator
    cvt.s.w $f8, $f8    # convert representation to float

    li $t1, 0           
    mtc1 $t1, $f10       # $f10 = current denominator
    cvt.s.w $f10, $f10   # convert representation to float

    li $t1, 0           
    mtc1 $t1, $f12       # $f12 = first fraction of denomintor
    cvt.s.w $f12, $f12   # convert representation to float

    li $t1, 0           
    mtc1 $t1, $f14      # $f14 = second fraction of denomintor
    cvt.s.w $f14, $f14   # convert representation to float

    li $t1, 0           
    mtc1 $t1, $f16       # $f16 = thridt fraction of denomintor
    cvt.s.w $f16, $f16   # convert representation to float

    li $t1, 0           
    mtc1 $t1, $f18        # $f18 = n
    cvt.s.w $f18, $f18    # convert representation to float

    li $t1, 1           
    mtc1 $t1, $f20        # $f12 = constant value of 1
    cvt.s.w $f20, $f20    # convert representation to float

    li $t1, -1           
    mtc1 $t1, $f22        # $f22 = constant value of -1
    cvt.s.w $f22, $f22    # convert representation to flaot

single_forward:
    mov.s $f24, $f18
    cvt.w.s $f24, $f24
    mfc1 $t2, $f24
    andi $t3, $t2, 1
    bnez $t3, odd

even:
    mul.s $f8, $f20, $f6        # current numerator when n is even
    
    mul.s $f30, $f2, $f18       # $f30 = 2n
    add.s $f12, $f30, $f2       # $f12 = (2n+2)
    add.s $f14, $f12, $f20      # $f14 = (2n+3)
    add.s $f16, $f14, $f20      # $f16 = (2n+4)
    mul.s $f10, $f12, $f14      # current denominator (2n+2)(2n+4)
    mul.s $f10, $f10, $f16      # $f10 = (2n+2)(2n+3)(2n+4)

    div.s $f24, $f8, $f10       # $f24 = result
    add.s $f0, $f0, $f24        # update the sum

    add.s $f18, $f18, $f20      # increment n counter
    mov.s $f24, $f18            # f24 = current n count
    cvt.w.s $f24, $f24          # convert representation to float
    mfc1 $t4, $f24              # 
    beq $a0, $t4, done

    j single_forward
    
odd:
    mul.s $f8, $f22, $f6       # current numerator when n is odd

    mul.s $f30, $f2, $f18       # $f30 = 2n
    add.s $f12, $f30, $f2       # $f12 = (2n+2)
    add.s $f14, $f12, $f20      # $f14 = (2n+3)
    add.s $f16, $f14, $f20      # $f16 = (2n+4)
    mul.s $f10, $f12, $f14      # current denominator (2n+2)(2n+4)
    mul.s $f10, $f10, $f16      # $f10 = (2n+2)(2n+3)(2n+4)

    div.s $f24, $f8, $f10       # $f24 = result
    add.s $f0, $f0, $f24        # update the sum

    add.s $f18, $f18, $f20      # increment n counter
    mov.s $f24, $f18            # f24 = current n count
    cvt.w.s $f24, $f24          # convert representation to float
    mfc1 $t4, $f24              # 
    beq $a0, $t4, done

    j single_forward


done:
    add.s $f0, $f0, $f4  # add 3 to result

    jr $ra

任何让我开始的提示或建议将不胜感激,谢谢!

I need to Calculate the value of pi (single-precision) using the first k terms of Nilakantha's series added in reverse order. I have the code for forward order which is given below. Now can someone help me to get started on how to go about the reverse order?

    li $t1, 0           # constant value of 0
    mtc1 $t1, $f0       # $f0 = current sum
    cvt.s.w $f0, $f0    # convert representation from 2's complement to IEEE float (not needed for 0)

    li $t1, 2           
    mtc1 $t1, $f2       # $f2 = constant value of 2
    cvt.s.w $f2, $f2    # convert representation of 2 to float

    li $t1, 3           
    mtc1 $t1, $f4       # $f6 = constant value of 3
    cvt.s.w $f4, $f4    # convert representation of 3 to float

    li $t1, 4           
    mtc1 $t1, $f6       # $f6 = constant value of 4
    cvt.s.w $f6, $f6    # convert representation of 4 to float

    li $t1, 0           
    mtc1 $t1, $f8       # $f8 = current numerator
    cvt.s.w $f8, $f8    # convert representation to float

    li $t1, 0           
    mtc1 $t1, $f10       # $f10 = current denominator
    cvt.s.w $f10, $f10   # convert representation to float

    li $t1, 0           
    mtc1 $t1, $f12       # $f12 = first fraction of denomintor
    cvt.s.w $f12, $f12   # convert representation to float

    li $t1, 0           
    mtc1 $t1, $f14      # $f14 = second fraction of denomintor
    cvt.s.w $f14, $f14   # convert representation to float

    li $t1, 0           
    mtc1 $t1, $f16       # $f16 = thridt fraction of denomintor
    cvt.s.w $f16, $f16   # convert representation to float

    li $t1, 0           
    mtc1 $t1, $f18        # $f18 = n
    cvt.s.w $f18, $f18    # convert representation to float

    li $t1, 1           
    mtc1 $t1, $f20        # $f12 = constant value of 1
    cvt.s.w $f20, $f20    # convert representation to float

    li $t1, -1           
    mtc1 $t1, $f22        # $f22 = constant value of -1
    cvt.s.w $f22, $f22    # convert representation to flaot

single_forward:
    mov.s $f24, $f18
    cvt.w.s $f24, $f24
    mfc1 $t2, $f24
    andi $t3, $t2, 1
    bnez $t3, odd

even:
    mul.s $f8, $f20, $f6        # current numerator when n is even
    
    mul.s $f30, $f2, $f18       # $f30 = 2n
    add.s $f12, $f30, $f2       # $f12 = (2n+2)
    add.s $f14, $f12, $f20      # $f14 = (2n+3)
    add.s $f16, $f14, $f20      # $f16 = (2n+4)
    mul.s $f10, $f12, $f14      # current denominator (2n+2)(2n+4)
    mul.s $f10, $f10, $f16      # $f10 = (2n+2)(2n+3)(2n+4)

    div.s $f24, $f8, $f10       # $f24 = result
    add.s $f0, $f0, $f24        # update the sum

    add.s $f18, $f18, $f20      # increment n counter
    mov.s $f24, $f18            # f24 = current n count
    cvt.w.s $f24, $f24          # convert representation to float
    mfc1 $t4, $f24              # 
    beq $a0, $t4, done

    j single_forward
    
odd:
    mul.s $f8, $f22, $f6       # current numerator when n is odd

    mul.s $f30, $f2, $f18       # $f30 = 2n
    add.s $f12, $f30, $f2       # $f12 = (2n+2)
    add.s $f14, $f12, $f20      # $f14 = (2n+3)
    add.s $f16, $f14, $f20      # $f16 = (2n+4)
    mul.s $f10, $f12, $f14      # current denominator (2n+2)(2n+4)
    mul.s $f10, $f10, $f16      # $f10 = (2n+2)(2n+3)(2n+4)

    div.s $f24, $f8, $f10       # $f24 = result
    add.s $f0, $f0, $f24        # update the sum

    add.s $f18, $f18, $f20      # increment n counter
    mov.s $f24, $f18            # f24 = current n count
    cvt.w.s $f24, $f24          # convert representation to float
    mfc1 $t4, $f24              # 
    beq $a0, $t4, done

    j single_forward


done:
    add.s $f0, $f0, $f4  # add 3 to result

    jr $ra

Any hint or suggestion to get me started will be appreciated Thank YOU!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文