EASy68K
http://www.easy68k.com/EASy68Kforum/

MULU overflow
http://www.easy68k.com/EASy68Kforum/viewtopic.php?f=6&t=1050
Page 1 of 1

Author:  JacobIsrael [ Wed Oct 26, 2011 9:05 pm ]
Post subject:  MULU overflow

Hi, I have some simple code:

Code:
*-----------------------------------------------------------
* Program : Code Test
*-------------------------------------------------------
START   ORG   $1000
   MOVE.L   #$FFF,D5
   MOVE.L   #2,D6
RPT   MULU   D6,D5
   CMP   #$FFFFFFFF,D5
   BNE   RPT
 
   STOP   #$2700

   END   START

But, when you try to max out D5 to FFFFFFFF,
it will not work.
Why? :(
MULU should give a 32-bit result.
Thanks for your help.
Code:

Author:  lee [ Thu Oct 27, 2011 10:09 am ]
Post subject: 

MULU has only word sized operands so ..

Code:
      MULU    d6,d5

.. multiplies the word in d5 by the word in d6 and puts the longword result in d5. If d6 and d5 both held the largest unsigned word value of $FFFF the result in d5 after the MULU would be $FFFE0001.

Author:  clive [ Thu Oct 27, 2011 3:20 pm ]
Post subject: 

Even if it were to support 32-bit multiplications instead of 16 by 16 into 32, you're ability to detect an overflow in this manner is flawed.

Specifically, what are the odds for all numbers that the result will be exactly 0xFFFFFFFF?

I'm pretty sure it's zero here because no two possible 16-bit source values can get that result. The 68K does not clamp results, nor signals invalid values in the source register, nor overflows. You need to confirm both source registers do not exceed 0xFFFF.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/