Department of Electrical and Computer Engineering

The University of Texas at Austin

EE 306, Fall 2008
Programming Assignment 2
Due: 21 October, 11:59 pm
Yale N. Patt, Instructor
TAs: Jeffrey Allan, Arvind Chandrababu, Eiman Ebrahimi, Aravind Jakkani, Khubaib,
        Allison Korczynski, Pratyusha Nidamaluri, Zrinka Puljiz, Che-Chun Su, Christopher Wiley

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.

  ...    ...  
  x3100    x5001  
  ...    ...  
  x5001    xD007  
  x5002    x0043  
  x5003    x0002  
  ...    ...  
  xA004    x0000  
  xA005    x0057  
  xA006    x0055  
  ...    ...  
  xD007    xA004  
  xD008    x004D  
  xD009    x0023  
  ...    ...  

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:
  ...    ...  
  x3100    x5001  
  ...    ...  
  x5001    xD007  
  x5002    x0043  
  x5003    x0002  
  ...    ...  
  xA004    x0000  
  xA005    x0057  
  xA006    x0055  
  ...    ...  
  xD007    xA004  
  xD008    x004D  
  xD009    x0023  
  ...    ...  

After running your program, it should look like this:

  ...    ...  
  x3100    x5001  
  ...    ...  
  x4000    x0057  
  x4001    x0055  
  x4002    x0003  
  x4003    x0043  
  x4004    x0002  
  x4005    x004D  
  x4006    x0023  
  x4007    x0057  
  x4008    x0055  
  ...    ...  
  x5001    xD007  
  x5002    x0043  
  x5003    x0002  
  ...    ...  
  xA004    x0000  
  xA005    x0057  
  xA006    x0055  
  ...    ...  
  xD007    xA004  
  xD008    x004D  
  xD009    x0023  
  ...    ...  

Hint 1: You're going to need some way of keeping track of which node you're looking at in the linked list.

Hint 2: You're going to need something similar for keeping track of where the next element goes in the array.

Hint 3: In order to test your program you will need to initialize memory to contain the address of the first node at location x3100 and the nodes of the linked list between x5000 and xEFFF. To do so, you can load a separate file containing memory initialization values into the simulator. For example the linked list shown in the example above would be initialized in memory as follows:
Create a new asm file (for example called data.asm) with the following text in it:
.ORIG x3100
.FILL x5001
.BLKW x1F00
.FILL xD007
.FILL x0043
.FILL x0002
.BLKW x5000
.FILL x0000
.FILL x0057
.FILL x0055
.BLKW x3000
.FILL xA004
.FILL x004D
.FILL x0023

Assemble the newly created file to produce a data.obj file. Then, load the data.obj file into the simulator. Don't forget to set the PC register to x3000 before running your program. Note this is just an example of how to initialize memory for testing your program. This is not the only test case your program should work with and you will not submit this test file to the submission system.


 

Notes:

  • The first line of your program must specify the memory address of the first instruction of your program. The LC-3 simulator will place your program starting at that address. For this assignment, you should place your program starting at x3000 .
  • When using a Windows machine, use the LC3Edit program to type in your programs. Your program file needs to be in plain text format. Please ask any TA if you have any questions.
  • Look in the Software and Documentation section for more help on how to use the simulator.
  • The file that you will submit for this assignment must be named list.asm.
  • To submit program 2, follow the submission instructions.
  • You should check out the software and documentation and the submission instructions for submitting your program well before deadline, so that you can get help from a TA if you can not figure out the mechanics by yourself.