#int atoi( char * str ) {   str in $a0
atoi:
#   int result = 0;    result in $t0
	li	$t0,0
#   int p;	       p in $t1
#   for ( p = 0; str[p] != 0; p++ ) 
	li  $t1,0
atoiLoopStart:
	move $t3,$t1
	add  $t3,$t3,$a0
	lb   $t2,($t3)              # str[p] now in $t2
	beq  $t2,$0,atoiLoopEnd
	
#   	if ( 0 <= str[p] && str[p] <= '9' ) {
  	
  	li   $t3,'0'
  	slt  $t3,$t2,$t3
  	bne  $t3,$0,atoiIfElse
  	
#    	  result = result * 10 + str[p]-`'0'`;
	subi	$t2,$t2,'0'
	li 	$t3,10
	mult	$t3,$t0
	mflo	$t0
	add	$t0,$t0,$t2
	j	atoiIfJoin
	
#       } else {
atoiIfElse:
#   	  return result;
	j	atoiLoopEnd
#   	}	
atoiIfJoin:
	addi $t1,$t1,1
	j atoiLoopStart
#    }
atoiLoopEnd:
	move  	$v0,$t0
	jr	$ra

#}
	