CS/COE 447: Spring 2010 Lab 12 YOUR NAME: YOUR PARTNER'S NAME: Each of you should hand in a hardcopy of your own solution. This lab will give you practice with linked lists to help you with PA3. The skeleton code for this lab can be found at: http://www.cs.pitt.edu/~wiebe/courses/CS447/Sp10/lab12.asm === PART 1: Understanding how a linked list is allocated Type and assemble the following code in Mars and look at the data section. .data .word 17,0x10010020, 8,0x10010018, 44,0x0, 15,0x10010000, 23,0x10010010, list: 0x10010008 *** Q1: At what memory addresses (in hex) are the following values stored: 17 ? ________________ 8 ? ________________ 44 ? ________________ 15 ? ________________ 23 ? ________________ The numbers 17, 8, 44, 15, 23 are the data values in the nodes of a singly-linked list. The number in the word that follows each of the data values is the address of the next node in the list. The word labeled "list" contains the address of the first node in the list. *** Q2: What is the data value of the first node in the list? ____ *** Q3: What is the address of the second node in the list? ____ The list can be traversed following the path indicated by the next pointer in each node. Let's draw the nodes in the list in the order they appear when traversing. *** Q4: Complete the following drawing: ---------------------- ---------------------- ---------------------- |list= +---->|data= | +->|data= | ---------------------- ---------------------- | ---------------------- |next= +--+ |next= +--+ ---------------------- ---------------------- | | ---------------------- ---------------------- ---------------------- | |data= |<-+ |data= |<-+ |data= |<-+ ---------------------- | ---------------------- | ---------------------- |next= | +--+next= | +--+next= | ---------------------- ---------------------- ---------------------- === PART 2: Printing the data values in a list In this part of the code you must write MIPS code that prints the data values in "list". Each value should appear in a single line. You may start with the following: .text main: lw $a0, list jal print_list li $v0, 10 #exit syscall ## # Procedure: print_list(list) # # Prints the elements of a linked list in the order the list is traversed. # # Arguments: # list ($a0) - address of the first node of a singly-linked list of 1-word # integers. # Algorithm: # // ptr->data: "data" field of the node pointed by "ptr" # // ptr->next: "next" field of the node pointed by "ptr" # ptr = list # while (ptr != 0) { # println(ptr->data); # ptr = ptr->next; # } # print_list: # complete this code!!! jr $ra