flat assembler
Message board for the users of flat assembler.

Index > Main > Int64 multiplication

Author
Thread Post new topic Reply to topic
CandyMan



Joined: 04 Sep 2009
Posts: 405
Location: film "CandyMan" directed through Bernard Rose OR Candy Shop
CandyMan 11 Oct 2012, 17:24
How do I implement signed int64 multiplication with overflow checking in 32-bit mode?
Thanks.

_________________
smaller is better
Post 11 Oct 2012, 17:24
View user's profile Send private message Reply with quote
ejamesr



Joined: 04 Feb 2011
Posts: 52
Location: Provo, Utah, USA
ejamesr 11 Oct 2012, 19:45
You'll have far fewer problems if you first convert this to unsigned multiplication. Check the sign of both numbers -- if just one of the numbers is signed, remember to make the answer signed; otherwise the answer will be positive.

Then use the classic method you learned in elementary school (you'll do four unsigned multiply operations), and add up the results keeping the components in the proper columns. There will be twice as many bits in the result as in the multiplier and multiplicand combined, so you may want to make 128 bits available to hold the answer.

Treat each 32-bit component as a column; so the answer has potentially four columns. If any part of the result spills over past the first 64 bits (into the last two columns), the number has overflowed. And if bit 63 is set, the number won't fit into a signed 64-bit number (there could be a boundary condition you have to test). And remember to make the answer negative if just one of the numbers was originally negative.

This should at least get you started... good luck!
Post 11 Oct 2012, 19:45
View user's profile Send private message Send e-mail Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2023, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.