- Feb 17, 2002
- 4,723
- 80
- 91
I can't seem to find much about 68K asm, and I'm not sure if what I have is correct... But lets say we have 2 positive integers of word length in the first two data registers... like so:
MOVE.W #10,D0
MOVE.W #3,D1
So now I wanna find the remainder of dividing D0 by D1. I can't find any instruction for modulus, so I figured I need to get creative... My idea is as follows:
edit: fixed error pointed out by ChristianV
CLR.L D2
MOVE.W D0,D2
DIVU D1,D2
SWAP D2
^^ so basically:
- Clear out all 32 bits of D2
- Copy the contents of D0 into D2's last 16 bits (word length)
- Divide D2 by D1... D2 should now have the remainder in the upper 16 bits? (i think)
- Swap the upper and lower words of D2...
- And now I can refer to D2.W as the remainder of D0 divided by D1?
^^ This seems okay in theory... but I really don't know. Any advice?
edit: This is confirmed working. Thanks. I'll leave this hear in the off chance that someone's searching for the same solution.
MOVE.W #10,D0
MOVE.W #3,D1
So now I wanna find the remainder of dividing D0 by D1. I can't find any instruction for modulus, so I figured I need to get creative... My idea is as follows:
edit: fixed error pointed out by ChristianV
CLR.L D2
MOVE.W D0,D2
DIVU D1,D2
SWAP D2
^^ so basically:
- Clear out all 32 bits of D2
- Copy the contents of D0 into D2's last 16 bits (word length)
- Divide D2 by D1... D2 should now have the remainder in the upper 16 bits? (i think)
- Swap the upper and lower words of D2...
- And now I can refer to D2.W as the remainder of D0 divided by D1?
^^ This seems okay in theory... but I really don't know. Any advice?
edit: This is confirmed working. Thanks. I'll leave this hear in the off chance that someone's searching for the same solution.