Department of Electrical and Computer Engineering
University of Texas at Austin
EE 379K
Fall 2000
Y. N. Patt, Instructor
TAs: Kathy Buchheit, Laura Funderburg, Chandresh Jain, Onur Mutlu, Danny Nold, Kameswar Subramanian, Francis Tseng, Brian Ward

Programming Assignment 1
Part 1 Due: October 15, 2000 11.59 pm
Part 2 Due: October 17, 2000 11.59 pm

Instructions:

1. You should do the programming assignment by yourself. Instructions on how to submit the assignment is provided at the end of this handout.
2. There are two parts to this assignment. In each part you will be asked to write a different program. You will therefore submit two programs, one for Part 1 and one for Part 2. Both programs should be written in LC-2 machine language. Read the instructions carefully and make sure you follow them.

Part 1 - A Program that shifts a bit pattern to the left by a certain amount (a number between 0 and 16, including 0 and 16)

Problem: In this part, you are asked to write a program in LC-2 machine language to shift a bit pattern some number of bits to the left and store the result in memory. The number of bits the bit pattern should be shifted is called the shift amount. Shift amount is a non-negative number between 0 and 16, inclusive (that is 0 and 16 are valid shift amounts). Your program should assume that the initial bit pattern to be shifted is in memory location x3100 and the shift amount is stored in memory location x3101. Using those values, your program should perform the left shift and store the result in memory location x3102. Your program should start at memory location x3000.

Example: If the memory location x3100 contains the bit pattern 1101000100001011 and memory location x3101 contains the value 0000000000000101 (decimal 5), then your program needs to shift 1101000100001011 5 bits to the left and store the bit pattern 0010000101100000 in memory location x3102. Note that when you shift a bit pattern n bits to the left, you fill the lowest n bits of the bit pattern with 0's.

Hint: What happens when you add a number to itself?

Simulator Hint: You can test your program by setting the values of memory locations x3100 and x3101 before you run your program on the LC-2 simulator. On UNIX machines (Sun, Linux) you can do this by using the "Set Values" option on the menubar and selecting the "Set Register or Memory" option. On Windows machines, you can click on "Simulate" in menubar and select "Set Value". Instead, you can just press F4 and the "Set Value" dialog box will pop up.

Part 2 - A Program that rotates a bit pattern to the left by a certain amount (a number between 0 and 16, including 0 and 16)

Problem: Now that you have done the left shift, we'll ask you to do something more exciting: rotating a bit pattern. Your task in this part is to write a program in LC-2 machine language to rotate a bit pattern some number of bits to the left and store the result in memory. The rotate amount (number of bits you rotate the bit pattern to the left) is a non-negative integer between 0 and 16, inclusive. Your program should assume that the initial bit pattern is in memory location x3100 and the rotate amount is stored in memory location x3101. Using those values, your program should perform the left rotation and store the result in memory location x3102. Your program should start at memory location x3000.

Example: If the memory location x3100 contains the bit pattern 1101000100001011 and memory location x3101 contains the value 0000000000000101 (decimal 5), then your program needs to rotate 1101000100001011 5 bits to the left and store the bit pattern 0010000101111010 in memory location x3102. Note that when you rotate a bit pattern n bits to the left, it is just like a left shift except that top n bits before the shift end up as the bottom n bits.

Notes and Suggestions:

• The first line of your programs must specify the memory address of the first instruction of your program. LC-2 simulator will place your program starting at that address. For this assignment, you should place your program starting at x3000 (the first line of your program should contain the bit pattern 0011000000000000).
• If you are using a Windows machine, use the LC2Edit program to type in your programs. On Sun and Linux workstations, pico, emacs, and vi are several of the text editors you can use. Your program file needs to be in plain text format. Please ask any TA if you have any questions.
When and how to submit: Both programs are due before 11.59 pm, October 15, 2000. The instructions on how to submit your program will be posted well before the due date.