0

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 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

That makes perfect sense. I was totally over-thinking that one. Thanks for the help.
1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.