# nested.s -- example program featuring a nested loop # This program just prints a box of *'s. # The nested loop in a HLL could have looked like this: # # for i = 1 to 10 # begin # for j = 1 to 15 # print("* "); # print("\n"); # end # # Purpose of registers: # $s1 = outer loop counter # $s2 = inner loop counter # $v0 = selects which I/O routine to perform # $a0 = holds base address of string (when we want to print a string) .data star: .asciiz "* " newline: .asciiz "\n" .text main: li $s1, 1 # set outer loop counter to 1 outer: li $s2, 1 # set inner loop counter to 1 inner: li $v0, 4 # print a star la $a0, star syscall addi $s2, $s2, 1 # increment inner loop counter ble $s2, 15, inner # have we done 15 inner iterations? li $v0, 4 # print newline at end of line of stars la $a0, newline syscall addi $s1, $s1, 1 # increment outer loop counter ble $s1, 10, outer # have we done 10 outer iterations? li $v0, 10 # end of program syscall