You must do the programming assignment by yourself. You are permitted to get help from ONLY the TAs and the instructor. The file you submit should be an assembly language file called list.asm. This is the only file you need to submit.
In this assignment, you are asked to write a program in LC-3 assembly language to retrieve the contents of a linked list (stored in memory) and store it in a new array in memory in the same order. The nodes in the linked list represent the users of a chatroom. Users pay for the time they spend in the chatroom, and must buy minutes ahead of time. Each user has a unique username which consists of a single ASCII character and a number of minutes remaining, 0 <= m <= 255. You must also find the user with the most minutes remaining, and store that user's username and minutes remaining in memory.
A linked list is a data structure made of nodes. Each node is comprised of k+1 words: one word containing the address of the location of the next node and k words of data. In our case, each node will consist of three words: the address of the next node, a word containing a single ASCII character, representing the username of a chatroom user, and one word of data, which is the number of minutes that user has remaining in her account.
You initially have only the address of the first node of a linked list. Using that information, you can get the data from the first node, and the address of the second node. If each node contains the address of the next node, what should the last node contain, since there is no next node? It is a convention that the address stored in the last node is a value known as NULL. In most machines, NULL is equal to 0. In this machine, it will equal x0000. What if there isn't even a first node? Then the address of the first node is set by convention to NULL. When we go looking for the first node, we look at that address, see that it is set to NULL, and know that we don't mean that there is a node at x0000, but instead that there is no node at all.
|
|
Your program should assume that the address of the first node is stored at memory location x3100. Further, assume that all the nodes are somewhere between x5000 and xEFFF. Make no other assumptions about the location of the rest of the nodes. Remember, the address of the first node may be set to NULL, indicating that there are no nodes in the list.
Your program should store the data in the list in order into an array starting at memory location x4003. Store the number of nodes in the array in x4002. Store the username and minutes remaining of the user with the largest number of minutes remaining in x4000 and x4001 respectively. You may assume that no nodes in the linked list will overlap with the finished array.
If there are no nodes in the list, set x4000 and x4001 to x0000. If there are ties for the maximum number of minutes, pick the first one in the list with that maximum value.
Your program should start at memory location x3000. Your program should be able to handle a list of any size such that the above assumptions hold true. For instance, we couldn't have a 65,000 node linked list, because it wouldn't fit in memory. We could however have a 100 node list. You don't know the length of the list before hand, so your program needs to handle every possible case.
For instance, if memory initially looked like this:
After running your program, it should look like this:
|