I want to make a programme that reads several characters with no particular limit but just pressing Enter (I found that the ascii code for the Enter key is 13, correct me if I'm wrong) and kind of "stitch" them together.
For example, if the user gives the characters '3', '4', '5', the programme should show the integer '345'. So, each character should match a bit.
I tried to play with the loop as below:
.text
.globl main
main:
add $t0, $zero, $zero #counter
loop:
li $v0, 12 #v0 = the character that was read
syscall
subi $v0, $v0, 48
#from the register column, I found that after the syscalls, the v0
#register always adds 48 to the given character
beq $v0, 13, exit #if Enter is given, exit from the loop
move $t1, $v0 #move the character to t1
sb $t1, ($t0) #store the character to t0
addiu $t0, $t0, 1 #point to the next spot of the t0
j loop
exit:
add $a0, $t0, $zero #load the contents of t0 to a0
li $v0, 1 #print the result
syscall
li $v0, 10
syscall
The error that shows at my awkardly written code is "Runtime exception at 0x00400020: address out of range 0x00000000" due to the "store byte" command.
Should I have give an offset?
Is the whole "store byte" thingy fundamentally wrong?
Is the given_character-48 each time necessary?
What should I do?