Академический Документы
Профессиональный Документы
Культура Документы
Theoretically there is no limit on the dimension of an This is a 6*8 array of bytes and would be
array. implemented in 68000.
The only difficulty in the implementing arrays of higher array dc.b v11,v12,v13,v14,v15,v16,v17,v18 *Row1
dimension is calculating the correct index values. dc.b v21,v22,v23,v24,v25,v26,v27,v28 *Row2
dc.b v61,v61,v63,v64,v65,v66,v67,v68 *Row6
A 2-dimensional array is made up of rows and columns.
These rows and columns are mapped into the 1- The array can be stored either in row or in
dimensional memory layout. column order.
32nd Lecture, Dr. Michael Manzke, Page: 1 32nd Lecture, Dr. Michael Manzke, Page: 2
32nd Lecture, Dr. Michael Manzke, Page: 3 32nd Lecture, Dr. Michael Manzke, Page: 4
1
2D Array Index
The most common is the row order method and it We need to calculate the appropriate index value. The
is this method we shall use. value is located at:
If we assume that a0 is pointing to the start of a0 + index where index = (row * 6 + col) * size
an array of word sized data values, and we use
d0.w as the index register, to access individual Example: What index is required to access array[3][4]?
elements of the 2D array requires a bit more
Index = (3 * 6 + 4) * 1
effort than with the 1D counterpart.
= 22
We wish to access : In general for a 2D array of element-size S, the correct index value
for the element located at array[row,col] is:
array [row][col]
(row * RowSize + col) * S
32nd Lecture, Dr. Michael Manzke, Page: 5 32nd Lecture, Dr. Michael Manzke, Page: 6
Higher Dimension
Array Higher Dimension Array
Extending to higher dimensions can be implemented by Again, be wary of odd aligned rows and columns. If
extending the dimension of the above formula. element size S are words or greater there is no chance
of errors.
For example the correct index for the value at
array[w,x,y,z] of a 4D array, of elements size S and of With elements of size byte, however, an array with odd
dimension SW * SW * SY * SZ is given by the dimensions will cause data following the array to be odd
expression: aligned, possibly requiring padding of a byte.
32nd Lecture, Dr. Michael Manzke, Page: 7 32nd Lecture, Dr. Michael Manzke, Page: 8
2
Arrays of Records Arrays of Records
32nd Lecture, Dr. Michael Manzke, Page: 9 32nd Lecture, Dr. Michael Manzke, Page: 10
3
Pseudo-Code Assembly Language
class Rec {
byte a,b,c; Because of the difference in size of the
}; elements of the 2 arrays, we need two
Rec Trip[20];
byte Max3[20]; separate index registers.
i=0;
while(i<20)
{ When implementing arrays traversal, a
x=Trip[i].a;
y=Trip[i].b;
different variable should be used for
z=Trip[i].c; each array and loop control variable.
r=Big3(x,y,z); returns largest of 3 nums.
Max3[i]=r;
i++;
}
32nd Lecture, Dr. Michael Manzke, Page: 13 32nd Lecture, Dr. Michael Manzke, Page: 14
32nd Lecture, Dr. Michael Manzke, Page: 15 32nd Lecture, Dr. Michael Manzke, Page: 16
4
Static & Dynamic Storage Dynamic Storage
32nd Lecture, Dr. Michael Manzke, Page: 19 32nd Lecture, Dr. Michael Manzke, Page: 20
5
Nodes A Four Node Linked List
A node has at least two items: Pointer
First item: Pointer field
Data structure Node 1 A3
Second item:
Pointer Node 2 i Null Pointer
Points to the next node in the liked list.
implements:
Node 1 A3 $008f 5670
Allocation of memory through: $008F 5676
System calls $ 0040 0000
6
Example: Add Node (one) Example: Add Node (two)
The pointer that holds the address of the
first node is implemented in a4.
Then, make the new node first in list by:
GETNODE is invoked to allocate memory for
Moving a5 (start address of new node) into a4
the new node. (pointer to first node in linked list).
Subroutine returns start address for node Copy the two new ASCII character into the
node in a5. data field of the new node.
Pointer field of new node must contain the
address of the previous first node.
Copy a5 in the pointer field 2(a5)
The first two bytes are used for data field .
32nd Lecture, Dr. Michael Manzke, Page: 25 32nd Lecture, Dr. Michael Manzke, Page: 26
$008f 5670
more nodes
32nd Lecture, Dr. Michael Manzke, Page: 27 32nd Lecture, Dr. Michael Manzke, Page: 28