// File: /home/cs255001/demo/asm/4-linked-list/List.java public class List { int value; // int typed variable takes up 4 bytes List next; // reference variable contains an address, also 4 bytes // instance methods omitted - not relevant for discussion } |
I will assume that a linked list has been created and the head element of the list is stored in this variable:
List head; |
List ptr; ptr = head; while ( ptr != null ) { System.out.println( ptr.value ); ptr = ptr.next; } |
How to run the program:
|
Output:
cheung@aruba> java ListMain 11 22 33 44 55 |
|
|
|
Example: we are given the address 7000 - which is the start address of some list object
Notice that:
|
The offsets used in linked list will be "computed" differently
In fact:
|
Note:
|
I will now show you how to "compute" the offsets to access various data fields defined in a linked list structure using 2 different List classes
// File: /home/cs255001/demo/asm/4-linked-list/List.java public class List { int value; // int typed variable takes up 4 bytes List next; // reference variable contains an address, also 4 bytes // instance methods omitted - not relevant for discussion } |
This picture shows the placement of the data fields value and next in a list element:
Therefore:
|
I will show you an assembler program example later....
public class List { int value1; // int typed variable takes up 4 bytes short value2; // short typed variable takes up 2 bytes short value3; // short typed variable takes up 2 bytes List next; // reference variable contains an address, also 4 bytes // instance methods omitted - not relevant for discussion } |
This picture shows the placement of the data fields value and next in a list element:
Therefore:
|
I will show you an assembler program example later....