## Department of Electrical and Computer Engineering

### The University of Texas at Austin

EE 306, Fall 2013
Programming Assignment 1
Due: October 3rd, 11:59 pm
Yale N. Patt, Instructor
TAs:Ben Lin, Mochamad Asri, Ameya Chaudhari, Nikhil Garg, Lauren Guckert,
Jack Koenig, Saijel Mokashi, Sruti Nuthalapati, Sparsh Singhai, Jiajun Wang

You must do every 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.

Counting "01" patterns 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 count the number of occurrences of the pattern "01" in a 16-bit word, and store the result back in memory. Counting the number of occurrences of the "01" pattern means counting the number of times the pattern "01" shows up in the entire 16 bit word.

Some examples:

1111111111111110 has 0 occurrences of "01"
0101010101010101 has 8 occurrences of "01"
0000000100000000 has 1 occurrence of "01"
1110110001100001 has 3 occurrences of "01"

Your program should assume that the input word is stored in memory location x3100. Your program should store the output count in memory location x3101. Your program should start at memory location x3000, and should halt the machine after storing the output to memory location x3101. So for example, if the memory location x3100 contains the word 1110110001100001, then your program should store the value 0000000000000011(which is 3 in decimal) in memory location x3101, then halt.

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

Hint 2: 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 the program 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 cause the "Set Value" dialog box to pop up.

Make sure you set a breakpoint before you run your program so that your program will stop just before it executes the trap instruction. This will allow you to examine the contents of x3101 after your program has finished executing, but before control is turned over to the operating system to halt your program.

Follow the following steps:
• Write your program: Type your program in the LC3Edit text editor. Your program file needs to be in plain text format. The first line of your program must specify the memory address of the first instruction of your program. 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). Each subsequent line of your program will consist of 16 consecutive 0s and 1s corresponding to the bits of that instruction. For example, you would represent the instruction to add the contents of R1 to the contents of R2 and put the result in R0 by: 0001000001000010. A program represented in this way is called a .bin file.
• Test your program: First convert your .bin file to an .obj file. Then load the .obj file into the LC-3 Simulator and test thoroughly by running it with multiple different input values. Read the Software and Documentation section for more help on how to use the simulator. In the real world, writing a program is never finished until the program has been thoroughly tested on lots of different input data. In fact, thorough testing separates the serious programmers from the dilettantes. Thorough testing means using odd-ball data (we call them "corner cases"), not just straightforward data.
• Submit your program: The program you are to submit is the .bin file. Save your .bin file, and give it the name count.bin. Follow the submission instructions for uploading your count.bin file for grading.
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.