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
除以10,如果商非零,用余数得到8,再除以10,然后如果商非零,再用余数除以零。
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.