# Print each element from an array of bytes. ARRAY_LEN = 5 .text main: # Locals: # - $t0: int i # - $t1: temporary result array_loop__init: li $t0, 0 # int i = 0; array_loop__cond: bge $t0, ARRAY_LEN, array_loop__end # while (i < ARRAY_LEN) { array_loop__body: li $v0, 11 # syscall 11: print_char # Method 1: performing the arithmetic # from scratch. # la $t1, array # (array # add $t1, $t1, $t0 # + i) # lb $a0, ($t1) # # syscall # putchar(*(array + i)); # Method 2: Letting mipsy generate the # appropriate instructions from this # pseudoinstruction. lb $a0, array($t0) # (array + i) syscall # putchar(*(array + i)); li $v0, 11 # syscall 11: print_char li $a0, '\n' # syscall # putchar('\n'); array_loop__step: addi $t0, $t0, 1 # i++; b array_loop__cond # } array_loop__end: li $v0, 0 jr $ra # return 0; .data array: .byte 'h', 'e', 'l', 'l', 'o' # char array[ARRAY_LEN] = {'h', 'e', 'l', 'l', 'o'};