# CSE 410 Sp09 Homework 2, part III # strlen function and test program. # Replace the empty implement of strlen with actual code, # and modify the main program to print three different strings # and their calculated lengths using appropriate calls to # strlen and prstr. # name: # Data declarations .data test: .asciiz "testing, 1, two, III, 100" out1: .asciiz "length of string >" out2: .asciiz "< is " newline: .asciiz "\n" .globl main .text # prstr: # Print a string and an integer (presumably the length of the string) # and a descriptive message. # on entry: $a0 - address of null-terminated string # $a1 - integer value # $ra - return address prstr: move $s0, $a0 # save string address in $s0 move $s1, $a1 # save number in $s1 (probably not needed) la $a0, out1 # print "length of string >" li $v0, 4 syscall move $a0, $s0 # print string argument li $v0, 4 syscall la $a0, out2 # print "< is " li $v0, 4 syscall move $a0, $s1 # print number li $v0, 1 syscall la $a0, newline # print newline li $v0, 4 syscall jr $ra # return # strlen: # Return the length of a null-terminated string # on entry: $a0 - address of the string # $ra - return address # on exit: $v0 - length of the string (excluding the \0 byte at the end) strlen: li $v0, -1 # REPLACE WITH ACTUAL IMPLEMENTATION jr $ra # beginning of main program main: # REPLACE THIS COMMENT AND THE FOLLOWING CODE SO IT COMPUTES THE LENGTH # OF THREE SEPARATE STRINGS AND PRINTS THE STRINGS AND THEIR # LENGTHS BY CALLING strlen AND prstr APPROPRIATELY. la $a0, test # argument to strlen (currently ignored) jal strlen move $a1, $v0 # print a string and result of strlen la $a0, test jal prstr end: li $v0, 10 # stop program syscall