Multi-Precision Arithmetic on MIPS

Posted by Rob on Stack Overflow See other posts from Stack Overflow or by Rob
Published on 2010-04-21T13:30:34Z Indexed on 2010/04/21 13:33 UTC
Read the original article Hit count: 245

Filed under:
|
|

Hi,

I am just trying to implement multi-precision arithmetic on native MIPS. Assume that one 64-bit integer is in register $12 and $13 and another is in registers $14 and $15. The sum is to be placed in registers $10 and $11. The most significant word of the 64-bit integer is found in the even-numbered registers, and the least significant word is found in the odd-numbered registers. On the internet, it said, this is the shortest possible implementation.

addu  $11, $13, $15    # add least significant word
sltu  $10, $11, $15    # set carry-in bit 
addu  $10, $10, $12    # add in first most significant word
addu  $10, $10, $14    # add in second most significant word

I just wanna double check that I understand correctly. The sltu checks if the sum of the two least significant words is smaller or equal than one of the operands. If this is the case, than did a carry occur, is this right?

To check if there occured a carry when adding the two most significant words and store the result in $9 I have to do:

sltu  $9, $10, $12    # set carry-in bit 

Does this make any sense?

© Stack Overflow or respective owner

Related posts about assembly

Related posts about assemblies