Re: [cc65] 16x16 multiply routine overflow detection

From: Ullrich von Bassewitz <uz1musoftware.de>
Date: 2010-01-19 19:35:19
Hi!

On Mon, Jan 18, 2010 at 05:20:39PM -0800, Shawn Jefferson wrote:
>    I’m trying to a slightly modified version of the tosumulax routine from
>    the runtime in one of my projects, and what I’d like to be able to do is
>    detect when the result may overflow the 2 bytes, and in that case just
>    return 65535.  The problem I have is that I don’t really understand the
>    routine very well, and can’t figure out where/how to do an overflow
>    check?  I was hoping someone here might be able to help, or at the very
>    least say it isn’t possible with this algorithm.

If you're using the snapshot, my suggestion would be to use the new
cc65_umul16x16r32 routine (which is declared with some other new stuff in
cc65.h). It multiplies two 16 bit numbers and generates a 32 bit result, so
it's easy to check for an overflow.

If you're not using the snapshot, my suggestion is to either use it or extract
the multiplication routine from there.

Regards


        Uz


-- 
Ullrich von Bassewitz                                  uz@musoftware.de
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Tue Jan 19 19:35:26 2010

This archive was generated by hypermail 2.1.8 : 2010-01-19 19:35:29 CET