How can I take mod of a number in assembly in Motorola M6800

折月煮酒 提交于 2019-11-26 18:33:56

问题


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.


回答1:


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.




回答2:


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;
}


来源:https://stackoverflow.com/questions/5189631/how-can-i-take-mod-of-a-number-in-assembly-in-motorola-m6800

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!