How to Parse an Integer in MIPS?

  • Thread starter iamhumble
  • Start date
  • Tags
    Mips
In summary, the conversation is about a person struggling with parsing out an integer in a MIPS class. They are attempting to parse out the digits 7 and 2 from a number stored in register $t1, but are having difficulty. The solution involves using a loop to divide the number by 10 and keeping track of the remainder.
  • #1
iamhumble
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:
Technology news on Phys.org
  • #2
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

1. What is MIPS?

MIPS (Microprocessor without Interlocked Pipeline Stages) is a reduced instruction set computer (RISC) architecture used in microprocessors.

2. How do you parse a number in MIPS?

To parse a number in MIPS, you need to use the instruction "li" followed by the desired register and the number you want to parse. For example, "li $t0, 5" will load the number 5 into register $t0.

3. What is the difference between parsing a decimal number and a binary number in MIPS?

Parsing a decimal number in MIPS is done using the "li" instruction, while parsing a binary number requires converting the binary number to decimal first using the "lui" (load upper immediate) and "ori" (OR immediate) instructions.

4. Can you parse negative numbers in MIPS?

Yes, negative numbers can be parsed in MIPS using the "li" instruction with a negative value, or by using the "subi" (subtract immediate) instruction to subtract a value from 0 and store the result in a register.

5. Why is parsing numbers important in MIPS?

Parsing numbers in MIPS is important because it allows the computer to understand and manipulate numerical data, which is essential for mathematical calculations and various other operations in computer programming.

Similar threads

  • Programming and Computer Science
Replies
4
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
4K
  • Programming and Computer Science
Replies
1
Views
2K
  • Programming and Computer Science
Replies
1
Views
7K
  • Programming and Computer Science
Replies
1
Views
6K
  • Programming and Computer Science
Replies
1
Views
7K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Programming and Computer Science
Replies
4
Views
7K
  • Programming and Computer Science
Replies
20
Views
31K
Back
Top