views:

157

answers:

2

I am currently learing MIPS for a class and wrote the below sample code.

# UNTITLED PROGRAM

.data   # Data declaration section

.text

       main:      # Start of code section

               li $t1, 72
           move $a0, $t1
           li $v0,1

       exit:
              li $v0, 10
              syscall

# END OF PROGRAM

As shown the value of '72' is stored in register $t1. Now, how do I parse out the '7' and '2' out?

A: 

Divide by 10, the modulo is your next digit, repeat until the result of division is 0. This assuming you're not working with floating point numbers.

Toon Van Acker
Wow, it was that easy! I will see if there is some optimization I can do such as shifting the bits. I'm off to a good start. Thanks.
A: 

Not a mips expert... but:

72 / F = 7 "7"

7 * F = 70

72 - 70 = 2 "2"

You can apply this logic using F * (number of total digits - 1) to get each individual digit.

-r

rtm242
I am not using floating point numbers so I am unsure what is being said here. I will have to look at the MIPS documenation to see what "F" actually is. I think it stands for floatin point.