Access to one character per line

I am using something like SPIMS or MARS with syscall functions.

I am reading a line (and this works because I can print it) as follows:

li $v0, 8
la $a0, string
li $a1, 256
syscall

However, I have a problem accessing a single character in a string. Therefore, if I want to access the first character and print it, I try to do this:

la $t0, string
lb $a0, ($t0)
li $v0, 4
sys call

If I try something like this:

la $a0, string
li $v0, 4
syscall

This prints the entire line as the line points to the entire line.

If I try something like:

la $a0, string
lb $a0, ($t0)
li $v0, 4
syscall

This gives me an error. I don’t understand why, though - is not a byte character long, and does it just load the first byte from the string into $ a0?

thank

+5
source share
1 answer

Syscall MARS, , 4, , $a0 "[ ", , .

, , 11 "print character", . , ( ):

la $t0, string
lb $a0, ($t0)
li $v0, 11
syscall
+10

All Articles