## LSU EE 3755 -- Fall 2013 -- Computer Organization # .data SAMPLE: .asciiz "a" .asciiz "This is our sample string." msg: .ascii "The length of the string,\n\t \"%/a2/s\",\n is %/v1/d\n" .asciiz "Have a nice day.\n" .text .globl __start __start: la $a0, SAMPLE jalr strlen nop addi $v1, $v0, 0 la $a2, SAMPLE addi $v0, $0, 11 la $a0, msg syscall addi $v0, $0, 10 syscall strlen: ## Register Usage # # $a0: Address of first character of string. # $v0: Return value, the length of the string. # # # addi $v0, $0, -1 addi $v0, $a0, 1 TOP: lbu $t0, 0($a0) bne $t0, $0, TOP addi $a0, $a0, 1 # nop # j TOP # addi $v0, $v0, 1 # DONE: jr $ra sub $v0, $a0, $v0 ####