机器语言中 OISC 中使用 SBN 的斐波那契数

发布于 2024-08-28 06:35:53 字数 263 浏览 4 评论 0原文

我想在 OISC 架构中使用 SBN 生成斐波那契数列。我最初的做法是先用汇编语言实现,然后再转换为机器语言。第一步涉及将 0 和 1 存储在 2 个寄存器中,然后从 0 中减去 1,并在后续步骤中重复减去 1。每次它都会生成一个负数,并且由于它是负数,因此它会分支并获取绝对值查找指令。

我的做法正确吗?我对 OISC 的含义感到困惑。如果我错了,请纠正我,如果我执行减法然后求绝对值,则意味着我每次都使用 2 条指令。或者是在 OISC 处理器中这两条指令同时完成,这意味着我的方法是正确的。

I want to generate fibonacci series using SBN in an OISC architecture. My initial approach is to implement it in assembly language first and then convert it to machine language. The first steps involve storing 0 and 1 in 2 registers and then subtract 1 from 0 and repeatedly subtract 1 in the consequent steps. Everytime it will generate a negative number and since its negative, it branches off and fetches the absolute value finding instruction.

Is my approach correct? My confusion in the meaning of OISC. Correct me if i'm wrong, if i perform a subtraction and then an absolute value finding, it means that that i'm using 2 instructions everytime. or is it that in the OISC processor both these instructions are done at the sametime which would mean that my approach is correct.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夏雨凉 2024-09-04 06:35:53

通用汇编指令可以由 OISC 指令的组合合成。例如,取自维基百科页面,添加:

ADD a, b == subleq a, Z
            subleq Z, b
            subleq Z, Z

以及BEQ

BEQ b, c == subleq b, Z, L1
            subleq Z, Z, OUT
        L1: subleq Z, Z
            subleq Z, b, c
       OUT: ...

重要的见解是,一旦拥有这些构建块,您就可以构建更复杂的块。例如,使用ADDBEQ您可以轻松实现计数循环(这对斐波那契很有用......)

因此您可以执行以下操作:

  1. 在a中实现斐波那契普通汇编语言(最多需要几行)
  2. 查看哪些指令可以替代可从 OISC 指令轻松合成的指令
  3. 使用 OISC 重写

Common assembly instructions can be synthesized from combinations of the OISC instruction. For example, taken from the Wikipedia page, addition:

ADD a, b == subleq a, Z
            subleq Z, b
            subleq Z, Z

And BEQ:

BEQ b, c == subleq b, Z, L1
            subleq Z, Z, OUT
        L1: subleq Z, Z
            subleq Z, b, c
       OUT: ...

The important insight is that once you have these building blocks, you can build more complex blocks. For instance, with ADD and BEQ you can easily implement a counting loop (which would be useful for Fibonacci...)

So you can do the following:

  1. Implement Fibonacci in a normal assembly language (should take a few lines at most)
  2. See what instructions you can substitute for instructions easily synthesizable from OISC instructions
  3. Rewrite using OISC
习ぎ惯性依靠 2024-09-04 06:35:53

有两种方法可以解决这个问题:

  • 您的数据结构包含真实的(正范围)斐波那契数;如果是这样,您确实需要进行一项计算和一项否定(您称之为绝对)步骤,即。每个整数最少 2 个。
  • 或者,您可以解决它的 0 补码:-1、-1、-2、-3、-5、-8...这样,您只需要简单地否定结果即可打印/提供等。它具有快速的一步计算,但是当您访问它时(即当您将其打印给用户时),它会产生很小的翻译成本。

You have 2 ways to about it:

  • Your data structure contains the true (positive range) Fibonacci numbers; if so, you'd need indeed to do one calculation and one negation (what you call absolute) step, ie. minimum 2 per integer.
  • Or, you could solve the 0-complement of it: -1, -1, -2, -3, -5, -8... in this way, you only simply need to negate the result to print/provide etc. That has fast 1-step calculation, but it comes at a small cost of translation when you access it (i.e. when you print it out to the user).
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文