Reputation: 1365
I have a question regarding the MULU instruction. One thing I've noticed is that suppose I have the value 000FFFFF in a data register. And then suppose I want to put in another F so that it contains 00FFFFFF. What I usually do is multiply the data register by 16 like so:
MULU #16, D4
And then I add another F by doing ADD instruction (so I get 00FFFFFF). But when I multiplied again on 000FFFFF, all the bits inside the data register end up going to zero (00000000). After that multiply, I will have 000FFFF0, and then the rest will follow. I still don't understand the reason for this. I looked up this example and I feel that it should work. I also noticed that the Extend, Carry, and Zero bits all go to true if I simply add 1 to 000FFFFF
Upvotes: 0
Views: 256
Reputation: 1698
I believe the reason for this result is due to the limitation of the multiplier in the 68000. IIRC it can only handle 16 bit values, and so when you start dealing with values beyond that you get this kind of result.
What others have stated is by far the most efficient way of multiplying by a value with a power of 2 (left shift). The same is true for division, in that a right shift will effectively divide the value.
Also, if you are working with signed values, make sure to use Arithmetic Shifts rather than Logical ones to preserve the sign (especially for division :) )
Upvotes: 0
Reputation: 1365
Do not use multiplication. Instead, use LSL.L #4, (register) and that will yield the result needed in a much better way.
Upvotes: 1