# MIPS assembly language example: Muito! # Author: Ney Calazans # Function: This program adds the text ", muito!" at the end of character string given # The name of the original string is Frase. # .text # Add what follows to the text segment of the program .globl main # Declare the label main to be a global one main: la $a0,Frase # Print Frase initial contents. Put Frase string address in $a0 li $v0,4 # Generate print string service code (4) in $v0 syscall # and execute syscall to print li $a0,'\n' # Print newline - generate newline in $a0 li $v0,11 # Generate print character service code (11) in $v0 syscall # and execute syscall to print the newline la $t0,Frase # get pointer to Frase fimFrase: lbu $t1,0($t0) # gets next char of Frase blez $t1,insert # if next char is the NULL character jump to insert addiu $t0,$t0,1 # else point to the next char j fimFrase # and continue look for the end of Frase insert: la $t1,muito # get pointer to string muito insertFrase: # we know muito is not the empty string, # thus we need not start testing it... lbu $t2,0($t1) # read char of muito sb $t2,0($t0) # store it at the end of Frase addiu $t1,$t1,1 # increment pointer to next char of muito addiu $t0,$t0,1 # increment pointer to the next char to add in Frase beq $t2,$zero,end # if the last inserted was the last char of muito (NULL), end j insertFrase # else, continue copying chars of muito. # now, return from main end: la $a0,Frase # Print Frase to see if it is ok li $v0,4 # Generate print string service code in $v0 syscall # and execute syscall to print li $v0,10 syscall # end the program .data muito: .asciiz ", muito!" Frase: .asciiz "Mamãe me ama" .space 20