tags:

views:

595

answers:

1

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.

+5  A: 

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.

drhirsch
Thanks. It makes sense why I couldn't find the status register :)Your answer works perfectly. Is there any place with tips on better MIPS coding?
twistadias
There are few. For me, meditation over other peoples source or looking a objdump -S does works. You can learn from the rare occassions, where a compiler does something right, but you can learn even more from the places, where they produce utter crap, as usual ;-)http://www.cs.unibo.it/~solmi/teaching/arch_2002-2003/AssemblyLanguageProgDoc.pdf does give some useful tips too.
drhirsch
Great solution. I love it when solutions to apparently diificult (IMHO) problems are this elegant.
Derek B.