Q: I can't read the operation properly, can you post some
code to call the read_string syscall?
A: OK. First you need to declare some space in memory to put
the string and associate a label with that memory. In the code below
this is the line buf: .space 10. Then you need to put
8 in $v0, the address of buf in $a0 and the maximum string length
you want to read including the null in $a1. If you try to use a
length of 1 the syscall will return immediately, since it needs 1
to store the terminating null, so use at least a value of 2!
.data
prompt: .asciiz "Enter an operation"
buf: .space 10 # reserves 10 bytes
.text
.align 2
main:
li $v0, 4 # syscall 4 is print string
la $a0, prompt
syscall
li $v0, 8 # syscall 8 is read string
la $a0,buf
li $a1,2 # reads 1 char plus the null
syscall
# the first character is now at address buf (still in $a0)
lbu $t0,0($a0) # go get the first char