3rdeye7
3rdeye7

Reputation: 536

Sum of two 64-bit unsigned integer QtSpim

Suppose registers $a1 and $a0 contain a 64-bit unsigned integer

A = $a1 × 2^32 + $a0

and registers $a3 and $a2 contain a 64-bit unsigned integer

B = $a3 × 2^32 + $a2.

How would I go about computing the sum of A and B and storing it in $v1, $v0 such that

A + B = $v1×2^32 + $v0. 

Not sure how I would approach this problem, any bit of help would be much appreciated.

Upvotes: 0

Views: 343

Answers (1)

gusbro
gusbro

Reputation: 22585

I would add pairwise the least significative words and the most significative words of each number, then "compute" the half-carry and increment the most significate word of the sum if carry occurred.

To "compute" the half-carry I would compare the least significative word of the sum with each operand. As you are computing unsigned addition you have half-carry if the sum is lower than either operand.

Something like this:

  addu $v0, $a2, $a0
  addu $v1, $a3, $a1
  bgt $a0, $v0, carry  
  ble $a2, $v0, done
carry:
  addiu  $v1, $v1, 1
done:  

Upvotes: 1

Related Questions