# Using array variables by storing them in the data segment directly # Anoop Sarkar # anoop at cs.sfu.ca .data # define a global variable: an array with two elements # the contents of the array are initialized to zero .globl myarray myarray: .word 0, 0 .text .globl main main: # let's say we want to put 2 into the array li $t0, 2 # $t1 contains the index into the array li $t1, 0 # next line implements: myarray[0] = 2 sd $t0, myarray + 0($t1) # next, we want to put 4 into the array li $t0, 4 # add sizeof(int) = 4 to $t1 to advance to next array location addi $t1, $t1, 4 # next line implements: myarray[1] = 4 sd $t0, myarray + 0($t1) # now, print out the array elements to check if it worked li $t1, 0 ld $a0, myarray + 0($t1) li $v0, 1 syscall li $t1, 4 ld $a0, myarray + 0($t1) li $v0, 1 syscall