views:

195

answers:

2

Using MIPS assembly if I prompt a user to input an integer how can I then take that integer and break it up into it's requisite parts?

Example:

                 # User inputs a number
li  $v0, 5  # read value of n
    syscall

I then store the value in $v0 in a temporary register, say $t0, and need to break it up into each part that makes it up. So, 308 has to be broken up into: 3, 0, and 8. I need to do this so that I can then square each of these parts and add them together.

The input value from the user has to be input as an integer.

thanks, nmr

+2  A: 

Divide by 10, use the remainder to get the 8, if quotient is non-zero, divide by 10 again and use then remainder to to the zero, if quotient is non-zero repeat.

Don
That makes perfect sense. I was totally over-thinking that one. Thanks for the help.
nmr
+1  A: 

This is @Don's answer, with a twist

$t0 contains the user input. (asume unsigned)

li   $t1,10
DIVU $t0,$t1 //divide by 10

mfhi $t2 //t2 contains the division result
mflo $t3 //t3 containts the division remainder

use beq, bgt to do the comparisons.

Some help

http://www.mrc.uidaho.edu/mrc/people/jff/digital/MIPSir.html

Tom