#program that calls bfind .data string: .space 128 .text .globl main main: subu $sp, $sp, 132 sw $ra, 0($sp) # allocate space on stack li $v0, 8 # get string addi $a1, $zero, 256 la $a0, string syscall jal bfind # find the first 'b' add $a0, $v0, $zero # print the index of 'b' addi $v0, $zero, 1 syscall lw $ra, 0($sp) addu $sp, $sp, 132 jr $ra #Here is procedure bfind .globl bfind bfind: add $t2, $a0, $zero add $t3, $zero, $zero addi $t1, $zero, 98 # ASCII 'b' loop: lbu $t0, 0($t2) # load the first byte beq $t0, $t1, done # if it's a 'b' we're done beq $t0, $zero, done # if it's a 0 we're done addi $t3, $t3, 1 addi $t2, $t2, 1 # increment pointer j loop # keep looping done: add $v0, $t3, $zero # return the result jr $ra