Array Basics
Arrays are contiguous blocks of memory that store multiple elements of the same type. In MIPS, arrays are typically stored in the data segment with a label marking the start address. Each element occupies a fixed amount of space based on its type (word, halfword, or byte).
Key Points:
- Arrays are contiguous memory blocks
- Elements are same size and type
- Use .word, .byte, or .float to declare
- la loads the base address
Example Code
.data
array: .word 10, 20, 30, 40, 50 # Array of 5 integers
bytes: .byte 'H', 'e', 'l', 'l', 'o' # Array of bytes
floats: .float 1.5, 2.5, 3.5 # Array of floats
.text
la $s0, array # Load address of array
lw $t0, 0($s0) # Load array[0] = 10
lw $t1, 4($s0) # Load array[1] = 20
lw $t2, 8($s0) # Load array[2] = 30Try It Yourself
1
2
3
4
5
6
7
8
9
10