How to Parse an Integer in MIPS?

  • Thread starter Thread starter iamhumble
  • Start date Start date
  • Tags Tags
    Mips
Click For Summary
The discussion focuses on a challenge in a MIPS programming class regarding extracting individual digits from an integer stored in register $t1. The user is attempting to parse the digits "7" and "2" from the value 7214. However, it is clarified that the register contains the entire integer, not the individual digits. To extract the digits, a loop is suggested that divides the number by 10 in each iteration while tracking the remainder, which represents the last digit. This method is essential for comparing the extracted digits against another number later in the program. The initial code provided does not implement this logic, leading to the confusion.
iamhumble
Messages
28
Reaction score
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:
Technology news on Phys.org
iamhumble said:
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
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

  • · Replies 4 ·
Replies
4
Views
1K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 4 ·
Replies
4
Views
5K
  • · Replies 1 ·
Replies
1
Views
8K
  • · Replies 1 ·
Replies
1
Views
7K
  • · Replies 2 ·
Replies
2
Views
5K
  • · Replies 1 ·
Replies
1
Views
8K
  • · Replies 4 ·
Replies
4
Views
7K
  • · Replies 20 ·
Replies
20
Views
33K
  • · Replies 5 ·
Replies
5
Views
10K