Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
387 views
in Technique[技术] by (71.8m points)

mips - Adding two 64 bit numbers in Assembly

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...