MIPS: How to parse a number

  • Thread starter iamhumble
  • Start date
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:
32,344
4,130
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.
 

Want to reply to this thread?

"MIPS: How to parse a number" You must log in or register to reply here.

Physics Forums Values

We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling
We Value Civility
• Positive and compassionate attitudes
• Patience while debating
We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving
Top