[prev] 7 [next]

1-d Arrays in MIPS

Can be named/initialised as:

vec:  .space 40
# could be either int vec[10] or char vec[40]

nums: .word 1, 3, 5, 7, 9   # int nums[6] = {1,3,5,7,9}
str: .byte 'a','b','c',0 # char str[] = {'a','b','c','\0'}
str2: .asciiz "abc"         # char str2[] = "abc"

Can access elements via index or cursor (pointer)

  • either approach needs to account for size of elements
Arrays passed to functions via pointer to first element
  • must also pass array size, since not available elsewhere