# A simple program to demonstrate loops, and array accessing # Written by Scott D. Anderson, 9/24/96 .text .globl main main: nop nop # # This code corresponds roughly to the following C code: # int array = { 16, 32, 128, 256, 4096, 8192 } # int i,x=0xFFFFFFFF # for( i=0; i<6; i++ ) x += array[i] # array[5] = x # .data x: .word 0xFFFFFFFF Array: .word 16 .word 32 .word 128 .word 256 .word 4096 .word 8192 .text sw $0,x # initialize x to zero move $s0, $0 # Use $s0 as i li $s1, 24 # Use $s1 for the upper bound of the loop move $s2, $0 # Use $s2 for the running sum loop1: bge $s0,$s1,done1 # while(s0