Primary contact for this homework: Pradip Vallathol [pradip16 at cs dot wisc dot edu]
You must do this homework in groups of two. Please write the full name and the student id of each member on every page and staple multiple pages together.
Important Notes:
Problems 2 and 4 ask you to submit your binary code as a text file (*.txt) to the Learn@UW dropbox. Additionally, they ask you turn in a printed screenshot of PennSim with your code. Your programs should start at address x3000 and end with a HALT instruction (0xF025). Set a breakpoint at the memory location of the HALT instruction and run the program until the simulator hits the breakpoint. Submit a screenshot of PennSim at this state as a hard copy.
See the LC-3 Edit and PennSim Tutorial Page on how to run your *.bin file on PennSim
Submission guidelines:
- For your your code submit only one archive file (*.zip or *.tar.gz) per group to the folder homework6.
- Name the file with the following convention: lastname1lastname2.zip or lastname1lastname2.tar.gz
- Your archive file should contain the following (The files MUST be named exactly like this):
- hw6_p2.txt - Binary code for problem 2
- hw6_p4.txt - Binary code for problem 4
- README.txt - Readme file that contains the names and student IDs for all members of your group and the HALT addresses for problem 2 and problem 4
- You can submit your code for problem 2 and 4 as many times as you want until 11:00 AM on Monday Nov. 5. After that time we will consider your latest submissions for grading.
See the Computing page for hints on screenshots.
Problem 1 (4 points)
Answer the following questions for the following snippet of code. Assume R0=0x1050, R1=0x0100, R2=0xC010, R3=0x0D01 before the instruction at 0x3000 is executed.
Address |
Instruction |
0x3000 |
0x1240 |
0x3001 |
0x0001 |
0x3002 |
0x127D |
0x3003 |
0x56C2 |
0x3004 |
0x927F |
- What is the value of the PC after the instruction at 0x3001 is executed?
- What is the value of R1 after the instruction at 0x3004 is executed?
Problem 2 (10 points)
Write a program in LC-3 binary code that searches for even numbers in 50 memory locations starting from 0x5250. Set R2 to the count of even numbers found. Your solution should use a looping construct. Comment each line of code and submit the binary code as a text file to the dropbox. The program should start at memory address x3000. Print out a screenshot of your code with the PC at the HALT instruction. Turn in the screenshot as a hard copy
To test you code use the scripts, found here. The file that you download is a zip file. On unzipping the package, you will find 3 script files (p2_test*.txt) and a "README.txt". The "README.txt" contains details on how to run these test scripts to verify your program.
Problem 3 (8 points)
The LC-3 has no Divide instruction. But just like multiplication can be implemented as a series of adds (see pages 165-166 in the textbook), division of positive integers can be implemented using subtraction. Consider an algorithm for dividing a positive integer in memory location M1 by a positive integer in memory location M2. The quotient is stored in memory location M3 and the remainder in memory location M4. Represent the algorithm as a flowchart by decomposing it into its basic constructs.
Problem 4 (8 points)
Write an LC-3 program which compares two numbers (A and B) in memory locations 0x302C and 0x302D and puts the greater number in memory location 0x302E. Take care that by "greater" we mean A > B and not |A| > |B|. Comment each line of code and submit the binary code as a text file to the dropbox. Print out a screenshot of your code running in PennSim. For the screenshot, make the value in memory location x302C to be x93F4 and the value in memory location x302D to be x0666. Your screenshot should show the PC at the HALT instruction and show the final value in memory location x302E (All of your code does not have to be completely visible). Turn in the screenshot as a hard copy