Abdul Ahad
Abdul Ahad

Reputation: 61

How to multiply two numbers in MIPS which gives product that is larger than 32bits?

Actually, my task is to multiply two 32bits number in MIPS which then generate the output of 64bits. Least significant 32bits are to be saved in 'lo' register and the remaining in 'hi' register to my understanding.

When I multiply 100000 and 200000 I get a817c800 in 'lo' register and 4 in 'hi' register

mult $t1, $t2 
    mflo $s0
    mfhi $s1 

enter image description here

Upvotes: 1

Views: 2136

Answers (1)

Martin Rosenau
Martin Rosenau

Reputation: 18493

When I multiply 100000 and 200000 I get a817c800 in 'lo' register and 4 in 'hi' register

Correct.

Because the result is 64 bits wide and you are using a 32-bit MIPS CPU, you need two registers to store the result.

In your code, the high 32 bits are in s1 and the low 32 bits are in s0. So the two registers s1 and s0 represent the 64-bit value 4a817c800 (hexadecimal) which is 20000000000 (decimal). And this is the correct result.

Your next question might be how you can print out a 64-bit number with qtspim. Unfortunately, I have no experiences with MIPS simulators (only with real MIPS CPUs), so I don't know if this is possible at all.

Upvotes: 1

Related Questions