How to Parse an Integer in MIPS?

  • Thread starter Thread starter iamhumble
  • Start date Start date
  • Tags Tags
    Mips
Click For Summary
SUMMARY

The discussion focuses on parsing integers in MIPS assembly language, specifically extracting the digits "7" and "2" from the value stored in register $t1. The user mistakenly believes that the digits are directly stored in $t1, while in reality, the register contains the value 7214. To extract individual digits, a loop that divides the number by 10 and tracks the remainder is necessary. This method allows for the correct parsing of digits for further comparison.

PREREQUISITES
  • Understanding of MIPS assembly language syntax and structure
  • Familiarity with register usage in MIPS, specifically $t1 and $a0
  • Knowledge of basic arithmetic operations in assembly, including division and modulus
  • Experience with control flow constructs such as loops in MIPS
NEXT STEPS
  • Implement a loop in MIPS to divide a number by 10 and extract digits using the modulus operation
  • Explore MIPS system calls for input and output operations, particularly for displaying integers
  • Study MIPS data types and their representation in memory
  • Learn about converting between decimal and hexadecimal representations in MIPS
USEFUL FOR

This discussion is beneficial for students learning MIPS assembly language, particularly those struggling with integer parsing and manipulation. It is also useful for educators teaching MIPS programming concepts.

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   Reactions: sysprog

Similar threads

  • · Replies 4 ·
Replies
4
Views
2K
  • · 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