views:

175

answers:

1

In my mips assembly code, I used the multi instruction to multiply 2 large numbers since the result could not fit in one register. This means that the number is saved in the hi and lo special registers. My problem is how do I print the result of the multiplication. I can access hi and lo and put them in other registers (i.e. $t0, $t1), but I do not know of a way to combine the two numbers in order to print the result. Thanks.

+1  A: 

(This answer kept deliberately high-level, since I'm pretty sure no one prints numbers in mips assembly unless they're doing it for a homework assignment.)

If you don't mind getting it in hex, it's no problem; just print one word in hex, and then the next one. Don't forget to include the leading zeroes on the second word! (Actually I think spim, which I presume you're using, can only print in base 10, so even this might be a bit of a chore).

If you want it in base 10, this problem quickly heads into the category I would call 'pain-in-the-ass'. In 'real life', I wouldn't bother; do the printing in C, some compiler guy somewhere solved all these problems for you. For homework, write yourself a function that divides the input by 10 repeatedly and you'll eventually end up with the digits to print out. If mips doesn't have a 64-bit divide instruction (couldn't tell you off the top of my head) this is going to be a pretty fun problem for you to solve.

Carl Norum