简体   繁体   English

模数68K组装

[英]Modulo in 68K assembly

I was wondering if there is a command/method to perform modulo in Motorola 68000 assembly? 我想知道是否有一个命令/方法在Motorola 68000程序集中执行模数?

I want to perform d4 mod 1000 and d3 mod 100. 我想执行d4 mod 1000和d3 mod 100。

Current I am using the following formula but this take several lines, 目前我正在使用以下公式,但这需要几行,

if a mod n then a - (n * int(a/n)) 如果一个mod n则a - (n * int(a / n))

I have seen this formula for d0 mod d1 我已经看到了d0 mod d1的这个公式

CLR.L D2
MOVE.W D0,D2
DIVU D1,D2
SWAP D2

Thanks for the answers. 谢谢你的回答。

The DIVU instruction does precisely what you are looking for. DIVU指令正是您正在寻找的。 When you perform DIVU , the long word of the destination is divided by the word of the source. 执行DIVU ,目标的长字除以源的字。 In your case, you wrote: 在你的情况下,你写道:

DIVU D1, D2

So, D2 is being divided by D1. 所以,D2被D1除。 In the quotient, there are two parts returned. 在商中,有两个部分返回。 The high order word of D2 will contain the remainder (the modulus) while the low order word contains the quotient. D2的高位字将包含余数(模数),而低位字包含商。 This is why you typically see a SWAP d2 . 这就是您通常会看到SWAP d2 This moves the remainder to the low order word. 这会将余数移到低位字。

  1. Perform division, result is quotient in bottom 16 bits, modulus in top 16 bits 执行除法,结果是底部16位的商,顶部16位的模数
  2. Set quotient to zero so... 将商设为零,这样......
  3. ..when you swap the modulus it is a valid 32 bit value ..当你交换模数时,它是一个有效的32位值

START
       DIVU  #1000,D4
       CLR.W D4             ; delete quotient
       SWAP  D4             ; modulus from top to bottom 16 bits

       DIVU  #100,D3
       CLR.W D3             ; delete quotient
       SWAP  D3             ; modulus from top to bottom 16 bits

One thing that this code doesn't handle is whether the result would be larger than #ffff(65535), for which you need extra code, possibly a test to check if D3/D4 is greater than the divisor shifted up by 16 bits. 这段代码无法处理的一件事是结果是否大于#ffff(65535),你需要额外的代码,可能是一个测试来检查D3 / D4是否大于向上移位16位的除数。

As the modulus will be a number between 0 and 99/999, you could alternatively use EXT.W after the swap instead of CLR.W before the swap. 由于模数将是0到99/999之间的数字,您可以在交换之后使用EXT.W而不是交换前的CLR.W。 Note that EXT sign extends a value. 请注意,EXT符号会扩展一个值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM