Department of Electrical and Computer Engineering

The University of Texas at Austin

EE 306, Fall 2011
Programming Assignment 1
Due: 11 October, 11:59 pm
Yale N. Patt, Instructor
TAs: Faruk Guvenilir, Milad Hashemi, Jennifer Davis, Garrett Galow, Ben Lin, Taylor Morrow, Stephen Pruett, Jee Ho Ryoo

You must do the programming assignment by yourself. You are permitted to get help ONLY from the TAs and the instructor. When you have completed the program, and tested it sufficiently so that you are comfortable that it works on any input (i.e., value initially stored in x3100), submit it for grading according to the submission instructions at the end of this handout.


Reverse the Bits in a 16-bit Bit Vector

Your Job: The addressability of the LC-3 is 16 bits; i.e., each memory location contains 16 bits of data. In this assignment, you are asked to write a program in LC-3 machine language to reverse the bits in a 16-bit word, and store the result back in memory. Reversing the bits means that bit 15 of the input becomes bit 0 of the output, bit 14 of the input becomes bit 1 of the output, and so on until bit 0 of the input becomes bit 15 of the output.

Your program should assume that the word to be reversed is stored in memory location x3100. Your program should store the reversed result in memory location x3101. Your program should start at memory location x3000.

Example: If the memory location x3100 contains the word 1110110001100001, then your program should store the value 1000011000110111 in memory location x3101.

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: You can set a bit in a word by using a bit mask. For example, if you know your word is 0000000010001100 and you want to set bit 8, use the bit mask 0000000100000000. Since bit 8 of your word is a 0, 0000000010001100 + 0000000100000000 = 0000000110001100. If you want to use a bit mask in your program, you can put the bit mask after your TRAP x25 (HALT) instruction (1111000000100101), and load the bit mask into a register.

Hint 4: Familiarize yourself with the software and documentation, and the submission instructions well before the deadline so that you can get help from a TA if you cannot figure out the mechanics by yourself. It is unreasonable to expect Professor Patt or a TA to help you submit your program at 11:45pm on the day it is due simply because you left this for the last minute, and have discovered that you do not know how to do it by yourself.

Simulator/Testing Hint: You can test your program by setting the value of memory location x3100 before you run your program on the LC-3 simulator. On Windows machines, you can click on "Simulate" on the menubar and select "Set Value". You can also just press F4 and the "Set Value" dialog box will pop up. Finally, double-clicking on the contents of a memory location will also pop up the "Set Value" dialog box.

Follow the following steps:

Note: We understand that to test your program, you must first create a .obj file. The .obj file is not to be submitted for grading. We will create a .obj file from your .bin file when we grade your program.