Jump to content
  • Advertisement
Sign in to follow this  
ShmeeBegek

MIPS multi-word integer arithmetic

This topic is 4854 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm fairly new to MIPS programming and I am wondering how one does multi-word integer arithmetic on MIPS (as there doesn't seem to be any facility like a carry bit). Obviously one could hack it in a variety of ways, but does anyone know of an elegant / standard way of doing it? In case there's any ambiguity, what I'm referring to is arithmetic on integers larger than 32 bits, perhaps 64 or 128 bits. Thanks, ~SPH

Share this post


Link to post
Share on other sites
Advertisement
Off the top of my head, say you had two numbers in $8 and $9, you could do

addu $10, $8, $9
sltu $11, $10, $9

$10 would hold the sum, and $11 would hold 1 if there was a carry out, and 0 if there wasn't.

Share this post


Link to post
Share on other sites

That makes sense for the most part, but wouldn't one use 'add' instead of 'addu' because one would want overflow?

Also this would mean that the high word would require 3 instructions to add (or 4 if there is an even higher word) right?


add $10, $8 , $9
sltu $11, $10, $9

add $10, $10, $6
add $10, $10, $7
add $10, $10, $11



Thanks, ~SPH

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!