Skip to main content
GameDev.net gamedev.net
🔒 Locked

MIPS multi-word integer arithmetic

Started by ShmeeBegek Aug 7, 2005 at 7:43 PM 1 replies 900+ views
Original Post
ShmeeBegek
ShmeeBegek
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
AIM ME: aGaBoOgAmOnGeR
SiCrane
SiCrane
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.
ShmeeBegek
ShmeeBegek

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
AIM ME: aGaBoOgAmOnGeR

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.