引用 21006091:
膜拜大神了!整套成本多少?
给你演示一个程序.
这里是一个8位无符号数除以8位无符号数的程序,应该还可以再写得高效率点,有符号除法复杂一点点.
RAM内存单元定义:
000000H : 余数
000001H : 被除数
000002H : 除数
000003H : 商
000004H : 计数
程序代码(下面部分用表达式形式来表示CPU的指令):
000000H A2A1A0 = 0x000000;
000001H RAM = 0x00;
000002H A2A1A0 = 0x000004;
000003H RAM = 0x07;
000004H A2A1A0 = 0x000003;
000005H A = RAM;
000006H RAM = A << 1;
000007H A2A1A0 = 0x000000;
000008H A = RAM;
000009H A2A1A0 = 0x000001;
00000AH B = RAM;
00000BH A = (A << 1) | (B >> 7 & 0x01);
00000CH B = B << 1;
00000DH RAM = B;
00000EH A2A1A0 = 0x000000;
00000FH RAM = A;
000010H A2A1A0 = 0x000002;
000011H B = RAM;
000012H A2A1A0 = 0x000016;
000013H 判断A - B没有借位跳转到000016H;
000014H A2A1A0 = 0x00001B;
000015H 无条件跳转到00001BH;
000016H A2A1A0 = 0x000000;
000017H RAM = A - B;
000018H A2A1A0 = 0x000003;
000019H A = RAM;
00001AH RAM = A + 1;
00001BH A2A1A0 = 0x000004;
00001CH A = RAM;
00001DH RAM = A - 1;
00001EH A2A1A0 = 0x000004;
00001FH 判断 A - 1没有借位跳转到000004H;
上面程序执行完成后结果在RAM内存单元里[s::lol]
大约250个时钟内完成计算