I am trying to optimize the following block of mips code and am struggling to find ways to reduce overall instructions or other ways of optimization. Thanks!
.data
Str: .asciiz "ABC"
Strempty: .asciiz " "
.text
.globl main
main:
jal strcpy #Jump to the strcpy subroutine
li $v0,4 #Code for printing strings
la $a0,Strempty #syscall to print the content of the copied string
syscall
li $v0,10 #Terminates the program
syscall
strcpy:
la $a0,Str #Get address of string y
la $a1, Strempty #Get address of string x
addi $sp,$sp,-4 #Adjust stack pointer to make room for doubleword
sw $s5,0($sp) #Push $s5 - i.e push contents of $s5 to the top of the stack
add $s5,$zero,$zero #i=0
L1:
add $t0,$s5,$a0 #$t0 = addr of y[i]
lbu $t1,0($t0) #t1 = y[i]
add $t2,$s5,$a1 #$t2 = addr of x[i]
sb $t1,0($t2) #x[i] = y[i]
beq $t1,$zero,L2 #Branches out when the null character is reached
addi $s5,$s5,1 #i=i+1
j L1 #Next iteration for L1
L2:
lw $s5,0($sp) #restore $s5
addi $sp,$sp,4 #pop the doubleword from the stack pointer
jr $ra #return to main