0
votes

I'm trying to design a basic calculator with MIPS. I promt the user for the first operand, the operator, and then the second operand. I get and store the first operand, but after the user enters the operator the prompt for the second operand appears on the same line, immediately after the user's input. Here's a sample of what I mean:

Enter first number: 8
Select operator: -Enter second number: 3
Result: 5
-- program is finished running (dropped off bottom) --

The "Enter second number" was printed right after the minus sign. I use read string, with length of string = 2 to get the operator. Here's the relevant code for that:

    GetOperator:
la $a0, prompt2     #Load prompt 2  
add $v0, $zero, 4   #Load syscall 4
syscall
la $a0, operator
add $a1, $zero, 2
add $v0, $zero, 8   #Load syscall 8
syscall         #Store the input string to memory
jr $ra

"operator" is a .word variable I declared under .data. I then use a syscall 4 to print the next prompt. I think there's just some subtle thing going on here that I'm missing. I'm still quite new with MIPS, so any pointers would be awesome.

1
There is no reason why this should be happening. Normally the line is advanced when the user presses the enter key. To investigate this issue we would really have to see the rest of the input sequence (i.e. what you call before you output the second prompt) - Konrad Lindenbach

1 Answers

0
votes

You could print a carriage return / linefeed sequence before the "Enter second number" string.

# 13=carriage return, 10=linefeed, 0=null terminator
CRLF: .byte 13,10,0

Use syscall 4 to print it.