Department of Electrical and Computer Engineering

The University of Texas at Austin

EE 306, Fall 2006
Programming Assignment 1
Due: 19 October, 11:59 pm
Yale N. Patt, Instructor
TAs: Aseem Bathla, Cameron Davison, Lisa de la Fuente, Phillip Duran, Jose Joao,
Jasveen Kaur, Rustam Miftakhutdinov, Veynu Narasiman, Nady Obeid, Poorna Samanta

You must do the programming assignment by yourself. You are permitted to get help ONLY from the TAs and the instructor. Instructions on how to submit the assignment will be provided on the webpage soon.

Left-rotate a 16-bit number N by B bit positions

In this assignment, you are asked to write a program in LC-3 machine language to left-rotate a 16-bit word N by a given number of bit positions B, and store the result back in memory. Your program should assume that the word N to be rotated is stored in memory location x3100 and the number of bit positions B is stored in memory location x3101. Your program should store the rotated result in memory location x3102. Your program should start at memory location x3000.

Example: If the memory location x3100 contains the word 0000111100001111, and memory location x3101 contains 0000000000000101, then your program should store the value 1110000111100001 in memory location x3102.

Note: You may assume that the value stored at memory location x3101 (the number of bit positions to left rotate by) is an integer between 0 and 15.

Hint 1: What happens when you add a number to itself? For example 1111000011110000 + 1111000011110000 = 1110000111100000.

Hint 2: How is bit 15 different from the other bits in a word?

Hint 3: Left rotating a 16-bit number by 3 bit positions is the same as left rotating the number by 1 bit position, and then left rotating again by 1 bit position, and then left rotating again by 1 bit position.

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-3 simulator. On UNIX (Linux) machines 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" on the menubar and select "Set Value". Instead, you can just press F4 and the "Set Value" dialog box will pop up.

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 (i.e. the first line of your program should contain the bit pattern 0011000000000000).
• If you are using a Windows machine, use the LC3Edit program to type in your programs. On the Linux workstations, pico, emacs (or xemacs), and vi (or gvim) 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.
• 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 leftrotate.bin.
• To submit program 1, follow the submission instructions.