jazzybazz
jazzybazz

Reputation: 1887

MC68000 assembly multiplication

Say we have the following:

MOVE.L #$1234ABCD,D0
MOVE.L #$45670012,D1
MULS   D0,D1

What will be the value of D1?

I notice the 146A values are the same as in the simulator, but where does the FFFA come from? Is the simulator wrong?

Upvotes: 2

Views: 2547

Answers (2)

Steve_I
Steve_I

Reputation: 61

The other comments already correctly tell what's going on. Here's just a (hopefully) clear summary:

The unsigned multiplication:

MOVE.L #$1234ABCD,D0
MOVE.L #$45670012,D1
MULU   D0,D1

will calculate like the following

0xABCD x 0x0012 = 0x000C146A

Which is the contents of D1 afterwards.

Whereas in the signed multiplication:

MOVE.L #$1234ABCD,D0
MOVE.L #$45670012,D1
MULS   D0,D1

0xABCD is the 2's-complement representation of the value -0x5433

-0x5433 x 0x0012 = -0x0005EB96

and that number in 32-bit 2's-complement is 0xFFFA146A which is the result in D1.

In both cases the upper words of the factors don't matter.

Edit (thx. Sep Roland and Peter Cordes):
In fact loading the registers with long values was part of the original question, but just adds to confusion.
The cpu will multiply two word sized values, and so it makes sense to load words:

MOVE #$ABCD,D0
MOVE #$0012,D1

PS: You can easily check the 32bit complement of the result with any hex calculator:
0x100000000 - 0x0005EB96 = 0xFFFA146A

Upvotes: 2

Thomas
Thomas

Reputation: 1401

I know 0 about Motorola's code, but I think its something to do with the fact your using a signed multiplier? Try using an unsigned multiplier.

Upvotes: 2

Related Questions