title: how to find character in string in MIPS assembly
body: <p>I'm new to MIPS assembly, I'm trying to make a program that finds the character just before <code>"?"</code>  </p>
  
  <p>However, for example when I enter input like <code>" abc?"</code>, output is <code>"c?"</code>. I can't find my mistake.</p>
  
  <p>code is here:</p>
  
  <pre><code>.data 
  
  buffer: .space 1024
  .text
  .globl main
  
  main:
  
  la $a0,buffer 
  li $v0,8 
  syscall 
  
  
  la $t1,buffer 
  
  
  loop: 
  lb $t2,($t1) 
  beq $t2,'?',loop1 
  add $t1,$t1,1 
  j loop
  
  loop1:
  sub $t1,$t1,1
  move $a0,$t1 
  li $v0,4 
  syscall 
  
  li $v0,10 
  syscall
  </code></pre>