0
votes

I'm trying to create an assembly-language program (in MIPS) that reads user-input values that are separated with newlines. I want to read a string that has an integer in it (for example, "A4" ,but instead, MIPS reads the string as "A" and the integer as "4". How do I make MIPS read the string as "A4" with syscall? Here's the bit of my code that I have so far, which is supposed to read a String on one line, and an integer on the next line.

buffer: .space 2
.text
.globl main
main:
li $v0, 8
la $a0, buffer
li $a1, 2
syscall
move $s0, $a0


li $v0, 5               
syscall
move $s1, $v0
1

1 Answers

2
votes

System call 8 reads at most $a1-1 characters, because it always NUL-terminates the string. So by setting $a1 to 2 and then inputting "A4" you will get the string "A\0" in buffer. If you want to be able to read 2 characters plus the NUL-terminator, set $a1 to 3 instead.