UART
Arrays
Christopher Mar
Array
Data structure
Array name is a pointer
Memory address of first element
Other elements accessed using offset (number of elements from first element)
Array Data Access
Address Contents
0x10000000 12
0x10000004 256
0x10000008 9
0x1000000C 37
0x10000010 654
0x10000014 81
0x10000018 0
0x1000001C 5309
register
lw
register
sw
Traversing an Array
Loop that increments offset
my_array[i]
Counter, i, is the offset from the base address
Traversing an Array
Problem: in PLP offset is a fixed value
Architectural choice limits lw/sw to 2 register accesses
Solution: save base address (if needed) and increment register pointing to array address
Traversing an Array
Useful Assumption:
1 character per word (4 bytes)
Each element is offset by 1 word from the previous element
An element can be accessed with a single lw or sw instruction
Array Space Allocation
Assembler Directive, .space
Example:
array_label:
.space 10
Leaves 10 words of memory empty
Copy address of space into register:
li $s0, array_label
More information can be found at:
http://progressive-learning-platform.github.io/instructions.html#space-allocation
Array Example in PLPTool