MIPS: How to parse a number

  • Thread starter iamhumble
  • Start date
  • #1
28
0
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:

Answers and Replies

  • #2
34,006
5,660
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.
 
  • Like
Likes sysprog

Related Threads on MIPS: How to parse a number

Replies
5
Views
7K
Replies
3
Views
3K
Replies
1
Views
11K
  • Last Post
Replies
4
Views
2K
Replies
3
Views
2K
  • Last Post
Replies
1
Views
1K
  • Last Post
Replies
3
Views
9K
  • Last Post
Replies
3
Views
31K
Replies
1
Views
8K
Top