Arrays in Mips Assembly Language Objective: Array Declaration
Arrays in Mips Assembly Language Objective: Array Declaration
LAB # 11
ARRAYS IN MIPS ASSEMBLY LANGUAGE
OBJECTIVE
To introduce how to implement array as an abstract data structure in MIPS assembly
language.
THEORY
Not like high level languages, Assembly language has no notion of an array at all.
Arrays like variables are treated as a block of memory that could be allocated
with a single directive, where the first element is given a label.
The array as the most important and most general data structure has the following
properties:
1. All elements must be the same size. The array is a homogeneous data
structure.
4. Traversing each element of an array needs an index or indices and the label
as the array's name.
ARRAY DECLARATION:
With reference to the above properties, in assembly language to declare an array it
requires:
1. A label name,
EXAMPLE:
.data
A01: .byte 'a', 'k', 'p', 5 # A01 is an array of 4 bytes: {'a', 'k', 'p', 5}
A02: .word 5, 6, -9, 7 # A02 is an array of 4 words: {5, 6, -9, 7}
B02: .space 40 #allocate 40 consecutive bytes, with storage uninitialized
# could be used as a 40-element character array, or a
# 10-element integer array;
# a comment should indicate which!
var1: .half 3 # create a single short integer variable with initial value 3
B03: .word -1:30 # allocate 40 consecutive words with each element
# initialized with -1.
EXAMPLE:
The following code fragment is to access the sixth element of table1:
.data
table1: .word 4, 5, 6, 7, 8, 9, 10, 21
.text
la $t0, table1
lw $t1, 20($t0)
addiu $t2, $t0, 20
lw $t1, 0($t2)