I’m currently learning how to code using MIPS and the QTSPIM emulator. I thought making a simple arithmetic calculator would be good practice, so I started coding.
So far, the program asks for a number, reads the number, asks for an operation (user has to input either the operation symbols +,-,*,/ or the initials a,s,m,d). The next step would be to compare the received input with something…
This is the part I’m stuck at.
My first thought was to have 4 registers with the characters already in them, so I tried
li $t5,a
li $t6,s
li $t7,m
li $t8,d
That, however, just gives me a syntax error. I tried a couple other similar ways, but kept getting an error.
My objective was to compare the user input to those 4 registers and then move on to the operation
beq $t2,$t5,add
beq $t2,$t6,sub
beq $t2,$t7,mul
beq $t2,$t8,div
Where $t2 contains the character input by the user. It then branches off to the appropriate label to perform the operation.
Is there an easier way to do this that I’m overlooking?
Thanks for your time.
Well, I managed to solve my own problem XD
The solution is a bit primitive, but it works…
Changed the operation prompt to
"1 for addition, 2 for subtraction, 3 for multiplication, 4 for division"and compared the user input with those,And the rest is just the operations themselves.
Thought I’d leave this here just in case someone else runs into a similar problem.
Maybe I’ll add memory and clear functions