2

I am trying to get input from a user in form of a string in MIPS.

There are two things I want this to do getting input, error checking for if the string is not equal to what I want.

Essentially what my idea here is that I want to grab the input and then check to see if the input is equal to any of the letters from A-P. If it is not equal to those, If it is not equal I want to have it loop until the user enters a value that is equal to these

Things that I have tried to consider using are beq or Branch if equal to. I cannot figure out how I would go about using this for comparing strings vs ints like you would traditionally.

Below is the code that I am trying to implement, this is obviously not right. But I wanted to give you guys an opportunity to see what I am trying to do so you can possibly give me some kind of direction to head towards solving this issue.

getGridInput

    li $v0, 8 #This read input for string
    la $a0, getGridPrompt
    syscall

    #if input is not equal to a-p, then jal getGridInput
    beq   $a0, "a",  getCellInput
    beq   $a0, "b",  getCellInput
    beq   $a0, "c",  getCellInput
    beq   $a0, "d",  getCellInput
    beq   $a0, "e",  getCellInput
    beq   $a0, "f",  getCellInput
    beq   $a0, "g",  getCellInput
    beq   $a0, "h",  getCellInput
    beq   $a0, "i",  getCellInput
    beq   $a0, "j",  getCellInput
    beq   $a0, "k",  getCellInput
    beq   $a0, "l",  getCellInput
    beq   $a0, "m",  getCellInput
    beq   $a0, "n",  getCellInput
    beq   $a0, "o",  getCellInput
    beq   $a0, "p",  getCellInput

    jal gelGridInput
Felcannon
  • 25
  • 4
  • [How to compare prestored string and user input string in mips](//stackoverflow.com/q/19041751) contains an example approach on how to approach asking for confirmation. It should be simple enough to apply the suggested fix (the person that copied that question code into an answer here certainly managed to do that). – Martijn Pieters Jul 22 '19 at 13:23
  • You're comparing the pointer; you need to `lbu` into a register. I mentioned that in my answer on the linked duplicate. – Peter Cordes Mar 31 '21 at 19:16

1 Answers1

0

well you are pretty much about done, the code function is overall fine except a few line you should change
"li $t1 yes" to "la $t1 yes"

As instruction: lb loads the byte from memory into the low order eight bits of the register.you need a extend to,so this would load the first byte of both. you can also use format "lb $t0, 0($t0)" which will probably work too

  • 1
    This appears to be a broken version of [How to compare prestored string and user input string in mips](https://stackoverflow.com/a/19042312), which had different code in the question. `la $t1, yes` makes no sense as an answer to this question. (And isn't what the linked answer suggested for the other question either: in that case they suggested using `lb` to load a `'y'` from memory *instead of* `la`. Of course even better would be `li $t1, 'y'`) – Peter Cordes Mar 31 '21 at 18:28