# MIPS: How to parse a number

I am taking a MIPS class this semester and for some reason I am having a tough time parsing out an integer. Can someone give me a hint what I am doing incorrectly here? Below, I am attempting to parse the "7" and "2" out that are currently stored in register $t1. The reason for this is I later on need to compare the "7" and "2" against another number. Thanks. Code: # UNTITLED PROGRAM .data # Data declaration section .text main: # Start of code section li$t1, 7214
move $a0,$t1
li $v0,1 exit: li$v0, 10
syscall
# END OF PROGRAM

Last edited by a moderator:

Related Programming and Computer Science News on Phys.org
Mark44
Mentor
I am taking a MIPS class this semester and for some reason I am having a tough time parsing out an integer. Can someone give me a hint what I am doing incorrectly here? Below, I am attempting to parse the "7" and "2" out that are currently stored in register $t1. The reason for this is I later on need to compare the "7" and "2" against another number. Thanks. Code: # UNTITLED PROGRAM .data # Data declaration section .text main: # Start of code section li$t1, 7214
move $a0,$t1
li $v0,1 exit: li$v0, 10
syscall
# END OF PROGRAM
Maybe you're having difficulty because neither 7 nor 2 are stored in register $t1. What's actually stored in$t1 is the bit pattern for 7124, which is 0000 0000 0000 0000 0001 1011 1101 01002, or 0x00001BD4 in base-16 or hexidecimal.

To get the digits out of a decimal (base-10) number, you would have to have a loop that divided the number by 10 each iteration, and kept track of the remainder. The problem as described here is pretty vague, so I can't give any more advice than that.

sysprog