Hallo,

MIPS works with words of 32 bit. But for universitiy, i have to add two 64 bit Integers numbers.

first of all, my idea was that i split the numbers and store them in two register. But that's only a theoretical idea. I have no idea how to realize in MIPS Code. How can i split the number? Anybody an idea?

Thank you very much

Hello,

greetings from the closest hood !

Which mips assembly?

The idea you sketched out is very good! It only functions this way.

# Assuming that the 64 bits int are always in two 32 bit regs ($11, $10) and ($21, $20), 
# where $11 and $21 contain the high order parts, the addition can be made by 

# 1) unsigned add both low order parts $10 + $20, result in $5

addu $5, $10, $20
 
# Then you need an add with carry instruction, 
# unfortunately mips assemblies lack of such nice instruction. 

# 2) So you must make use of sltu instruction, set carry in $4:

sltu $4, $5, $20  # fast way to determine carry of $5 = $10 + $20 

# 3) Now add with carry can be carried out: 

addu $4, $4, $11   # carry + first high order part $11
addu $6, $4, $21   # intermediate result + second high order part $21, result in $6

# 4) Finally, did we even do a 65 bit addition?

sltu $4, $6, $21  # carry of last addu set in $4.

### Final result is: 
### ($4, $6, $5), where $4 is last carry, $6 high order and $5 low order part of 64 bit result. 

# Attention: Above assembly not tested! If you find any error, pls tell me.

Well, that's all what I could remember of vintage mips r3000, hopefully, that some more advanced R.I.P. mips machines also function similar to this void-of-add-with-carry era, or they had even got that missing instruction, what you should really check for your current mips machine.

Happy mipsing!

-- tesu

so, so, doing excercises at LMU

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.