如何在摩托罗拉 M6800 中对数字进行取模

发布于 2024-10-20 03:23:14 字数 56 浏览 2 评论 0原文

我如何在摩托罗拉 M6800 的汇编中取数字的 mod,例如 a%9。请告诉我应该使用哪些助记符。

How can I take mod of a number for instance a%9 in assembly in Motorola M6800.Please tell me which mnemonics should I use.

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

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

发布评论

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

评论(2

万劫不复 2024-10-27 03:23:14

最后,如果没记错的话,6800没有除法指令(6809中添加的IIRC),所以你必须自己实现除法(或者,如果你不关心速度,只需减去重复除数,直到结果小于除数,这就是余数)。

要计算余数(不除除)实际上在二进制中非常容易:

  1. 将除数向左移动,直到它大于被除数,
  2. 将其右移一位
  3. 如果小于被除数,则从被除数中减去它,
  4. 重复步骤 2 和 3,直到被除数剩下的部分小于除数
  5. 这就是余数

例如,让我们计算 127 除以 9 后的余数。我们首先将 9 左移:

127 = 0111 1111
9   = 0000 1001

左移直到得到:

  0111 1111
  1001 0000

重复移位和相减:

      0111 1111
-     0100 1000
=     0011 0111

      0011 0111
-     0010 0100
=     0001 0011

      0001 0011
-     0001 0010
=     0000 0001

因为 1 小于 9 ,我们得到余数: 1. 如果你想检查一下,9x14=126。

At last if memory serves, the 6800 doesn't have a division instruction (IIRC that was added in the 6809), so you'll have to implement division on your own (or, if you don't care about speed, just subtract the divisor repeatedly until the result is less than the divisor, and that's your remainder).

To just figure the remainder (without the division) is actually pretty easy in binary:

  1. shift the divisor left until it's larger that the dividend
  2. shift it right one place
  3. If that's smaller than the dividend, subtract it from the dividend
  4. repeat steps 2 and 3 until what's left of the dividend is smaller than the divisor
  5. That's your remainder

For example, let's figure the remainder after dividing 127 by 9. We start by shifting 9 left:

127 = 0111 1111
9   = 0000 1001

shift left until you get:

  0111 1111
  1001 0000

Repeatedly shift and subtract:

      0111 1111
-     0100 1000
=     0011 0111

      0011 0111
-     0010 0100
=     0001 0011

      0001 0011
-     0001 0010
=     0000 0001

Since 1 is smaller than 9, we have our remainder: 1. In case you want to check that, 9x14=126.

甜宝宝 2024-10-27 03:23:14

使用简单的 68k

#include <iostream>
using namespace std;
int main ()
{

    {cout << "THE MULTIPLES OF THREE FROM 1-30 ARE: " <<endl;
    int a;
    int sum =0;
    for (a=1; a<=30; a++)
    {if ((a%3) == 0)
    {cout <<a << "\n" <<endl;
    sum =sum+a;
    }}
    cout <<"\tSUM = " <<sum<<endl;
    }
    system ("Pause");
    return 0;
}

using easy 68k

#include <iostream>
using namespace std;
int main ()
{

    {cout << "THE MULTIPLES OF THREE FROM 1-30 ARE: " <<endl;
    int a;
    int sum =0;
    for (a=1; a<=30; a++)
    {if ((a%3) == 0)
    {cout <<a << "\n" <<endl;
    sum =sum+a;
    }}
    cout <<"\tSUM = " <<sum<<endl;
    }
    system ("Pause");
    return 0;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文