# 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.

## 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 on other sites
Off the top of my head, say you had two numbers in $8 and$9, you could do
addu $10,$8, $9sltu$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 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 , $9sltu$11, $10,$9add  $10,$10, $6add$10, $10,$7add  $10,$10, \$11

Thanks, ~SPH

1. 1
Rutin
69
2. 2
3. 3
4. 4
5. 5

• 21
• 10
• 33
• 20
• 9
• ### Forum Statistics

• Total Topics
633420
• Total Posts
3011793
• ### Who's Online (See full list)

There are no registered users currently online

×