go to previous page   go to home page   go to next page hear noise

Answer:

Of course.


List Header

List Header

When a dynamic data structure is constructed, it is common to have a field in main memory that points to the start of the structure. The picture shows this. The symbolic address first contains the address of (points to) the first node of the linked list. Sometimes a field like this is called a header to the linked list.

(Note: the first node is called the head, the field that points to it is called the header. Unfortunately people are not consistent about this.)

Now the address of the first node is contained in two places (both colored red). Here is the code that does this:

        # create the first node 
        li      $v0,9             # allocate memory
        li      $a0,8             # 8 bytes
        syscall                   # $v0 <-- address
        move    $s1,$v0           # $s1 = &(first node)
        
        # copy the pointer to first
        sw       , 
        
        # initialize the node
        li      $t0,1             # store 1
        sw      $t0,0($s1)        # at displacement 0
        
        # create the second node 
        . . . .    
        
        .data
first: .word  0    # address of the first node

QUESTION 6:

Fill in the blanks to complete the code.