You must do every programming assignment by yourself. You are permitted to get help ONLY from the TAs and Dr. Patt. When you have completed the program, and tested it sufficiently so that you are comfortable that it works on any input (i.e., the value initially stored in location x3050), submit it for grading according to the submission instructions at the end of this handout.
Programming Assignment 1: Determine whether a number is a power of 2 or not.
Your Job: In this assignment, you are asked to write a program in LC-3 machine language that checks a positive 2's complement number to determine if it is a power of 2. The number is stored in memory location x3050. If the number is a power of 2, your program should store x0001 in memory location x3051. If the number is not a power of 2, your program should store x0000 in memory location x3051. Your program should start at memory location x3000, and should halt the machine after storing the output.
Hint 1: What is unique about the binary representations of powers of 2?
Hint 2: What happens when you add a number to itself? For example 00110111 + 00110111 = 01101110.
Hint 3: How can you check if bit 15 of a register is 0 or 1?
Hint 4: How can you use the knowledge from hints 2 and 3 to check if bit 9 of a register is 0 or 1? (hint added- 10/03/17)
Hint 5: 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 x3050 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 content of the location x3050 after your program has finished executing, but before control is turned over to the operating system to halt your program.Follow the following steps: