Homework 3: Part 1
An LC-3 machine code program that counts the number of bits set in a word

Due

Tuesday, November 13, 2007 at 11:59 pm

Outcomes

After successfully completing this assignment, you will be able to...

Before Starting

Read Chapters 4 and 5. Also, do Lab 1 to learn how to use the editor and simulator for the LC-3.

Description of Problem - Count the number of bits that are set in a 16-bit word.

Using LC3edit, create a file named count.bin. Your task is to write an LC-3 machine code program that counts the number of bits set to 1 in a 16-bit word. Your program expects that R0 will contain the address of the word to be tested (in other words, before executing your program, you should manually enter the address of the word you will test into R0). Upon completion of the program, the answer should be in R1. Your program should begin at memory location x3000.

Example: If the machine is initialized with these values:

R0:  x3050
memory location x3050:  x8055
then upon completion of your program R1 should contain the value x0005.

Hint: Recall from our class discussion that adding a number to itself effectively shifts the bit pattern to the left by one bit position.

You will use the solution to this problem in Part 2 of Homework 3 next week.

Documentation and Formatting

Your program should include a thorough and clear explanation of the process that you went through to come up with a machine code solution to the given problem. The explanation should be included as a comment at the top of your .bin file. Program documentation and formatting will be worth 50% of the grade for this program - your explanation should not be considered an afterthought to coding. It serves to document your thought process prior to coding and illustrates your understanding of the problem. It will serve as your outline when you code your solution. It will also serve as a guide to the TA who is trying to grade programs consisting entirely of 0's and 1's. It should contain (at least) the following information:

When coding the instructions themselves, leave a space between each field in the instruction, as we did in lab. For example, the following AND instruction is separated into its component parts (opcode field, destination and source registers, immediate bit, immediate value):

0101 001 001 1 00000     ;clear R1, to be used as the running sum
Unlike programs written in higher-level languages, machine code programs should have a comment for every line of code. Also, main sections of code should be preceded by explanatory comments.

Deliverables

You must use turnin to submit your LC-3 file count.bin before 11:59pm on Tuesday, November 13. Make sure you include your name in a comment at the top of your file.