Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modulo in 68K assembly

I was wondering if there is a command/method to perform modulo in Motorola 68000 assembly?

I want to perform d4 mod 1000 and 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))

I have seen this formula for d0 mod d1

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

Thanks for the answers.

like image 403
Dartuso Avatar asked Oct 13 '17 22:10

Dartuso


1 Answers

The DIVU instruction does precisely what you are looking for. When you perform DIVU, the long word of the destination is divided by the word of the source. In your case, you wrote:

DIVU D1, D2

So, D2 is being divided by 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. This is why you typically see a SWAP d2. This moves the remainder to the low order word.

like image 125
David Hoelzer Avatar answered Oct 18 '22 20:10

David Hoelzer