Homework 3: Part 1
An LC-3 machine code program that rotates a 16-bit word


Tuesday, November 16 at 5pm


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

Rotate a bit pattern n bits to the left

Using LC3edit, create a file named rotate.bin. Your task is to write an LC-3 machine code program that rotates a 16-bit word n bits to the left, where n is a non-negative integer between 0 and 16, inclusive. Your program should assume that R2 contains the address of the bit pattern to be rotated (in other words, before executing your program, you should manually enter the address of the word to be rotated into R2). Your program should also assume that the number of bit positions to rotate has been entered into R5. Upon completion, the rotated value should be stored in R4. Your program should begin at memory location x3000.

Example: If the original bit pattern is 1000 0000 0101 0101 (x8055), and the number of bits to rotate is 0000 0000 0000 1000, then upon completion of your program R4 should contain the value 0101 0101 1000 0000 (x5580).

Hint: Recall from our class discussion that adding a number to itself effectively shifts the bit pattern to the left by one bit position. A 1-bit left rotation is just like a 1-bit left shift except that the leftmost bit (bit 15) ends up as the rightmost bit (bit 0).

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.


You must use turnin to submit your LC-3 file rotate.bin before 5pm on Tuesday, November 16. Make sure you include your name and section number as comments at the top of your file.