.data array: .word str1,str2,str3,0x0 str1: .asciiz "Hello World\n" str2: .asciiz "Hi there CS 447!\n" str3: .asciiz "Welcome to the Burgh!\n" .text la $a0,array li $a1,' ' li $a2,'_' jal findreplacearray la $a0,str1 li $v0,4 syscall la $a0,str2 syscall la $a0,str3 syscall li $v0,10 syscall # $a0 = address of the string # $a1 = source character to be replaced # $a2 = new character findreplace: move $t0,$a0 findreplaceloop: lbu $t1,0($t0) beq $t1,$0,findreplaceexit # null terminator addi $t0,$t0,1 bne $t1,$a1,findreplaceloop # not the replacement character sb $a2,-1($t0) j findreplaceloop findreplaceexit: jr $ra # $a0 = address of array, terminated by 0 of strings # $a1 = source character to be replaced # $a2 = new character findreplacearray: addi $sp,$sp,-8 sw $ra,0($sp) sw $s0,4($sp) move $s0,$a0 findreplacearrayloop: lw $a0,0($s0) # get the address of a string beq $a0,$0,findreplacearrayexit jal findreplace addi $s0,$s0,4 j findreplacearrayloop findreplacearrayexit: lw $ra,0($sp) lw $s0,4($sp) addi $sp,$sp,4 jr $ra