Department of Electrical and Computer Engineering
University of Texas at Austin
EE 306
Fall 2004
Y. N. Patt, Instructor
Siddharth Balwani, Linda Bigelow, Tommy Buell, Jeremy Carrillo, Aamir Hasan,
Danny Lynch, Rustam Miftakhutdinov, Veynu Narasiman, Vishal Parikh, Basit Sheikh, TAs

Programming Assignment 1
Due: Sunday October 17, 2004 11:59 pm

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.

Count the number of ones in a 16-bit word

In this assignment, you are asked to write a program in LC-3 machine language to count the number of ones in a 16-bit word and store the number in memory. Your program should assume that the word in which we are counting the number of ones is stored in memory location x3100. Your program should count the number of ones in the word and store the result in memory location x3101. Your program should start at memory location x3000.

Example: If the memory location x3100 contains the word 1101000100001011, then your program should store the value 0000000000000111 (decimal 7) in memory location x3101.

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

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

Simulator 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 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.

Notes and Suggestions: