Adding two 64 bit numbers in Assembly

user156903 picture user156903 · Aug 15, 2009 · Viewed 13.9k times · Source

So I am learning MIPS using the SPIM simulator and im stuck on this problem.

I want to add two 64 bit numbers which are stored in four 32 bit registers. So I add the LO bytes and then the carry and the HI bytes. But there is no adc/addc command i.e. add with carry.

So I would have to add the carry bit in the status register. But, how exactly do I read this register?

If $t0 is temporary register 1, then what is the equivalent of the status register which holds the carry flag?

I have googled a lot I still can't find any examples that even use the status register.

Answer

Gunther Piez picture Gunther Piez · Aug 15, 2009

Add $t2 $t3 + $t4 $t5, result in $t0 $t1

addu  $t1, $t3, $t5    # add least significant word
sltu  $t0, $t1, $t5    # set carry-in bit 
addu  $t0, $t0, $t2    # add in first most significant word
addu  $t0, $t0, $t4    # add in second most significant word

For the second part of your question, there is no status register. None at all. Nada.