lab5_ex1.asm (850B)
1 .eqv SYS_PRINT_WORD 1 2 .eqv SYS_PRINT_STRING 4 3 .eqv SYS_READ_STRING 8 4 .eqv SYS_EXIT 10 5 6 .data 7 str: .space 17 # + 2 bytes to include '\n' and '\0' 8 len: .asciiz "strlen: " 9 revstr: .asciiz "reverse: " 10 11 .text 12 .globl main 13 14 main: 15 # read input string 16 li $v0, SYS_READ_STRING 17 la $a0, str 18 li $a1, 17 19 syscall 20 21 # init strlen counter 22 li $t0, 0 23 24 strlen: 25 lb $t1, str($t0) 26 beqz $t1, exit 27 addi $t0, $t0, 1 28 j strlen 29 30 exit: 31 li $v0, SYS_PRINT_STRING 32 la $a0, len 33 syscall 34 35 li $v0, SYS_PRINT_WORD 36 la $a0, 0($t0) 37 syscall 38 39 li $v0, SYS_EXIT 40 syscall