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 |
Comments |
0x3000 |
0x1240 |
R1 = R1 + R0 |
0x3001 |
0x0001 |
NO-OP |
0x3002 |
0x127D |
R1 = R1 - 3 |
0x3003 |
0x56C2 |
R3 = R3 AND R2 |
0x3004 |
0x927F |
R1 = NOT(R1) |
- What is the value of the PC after the instruction at 0x3001 is executed?
0x3002
- What is the value of R1 after the instruction at 0x3004 is executed?
0xEEB2
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.
Sample Solution:
0011 0000 0000 0000 ; setting start to x3000
0010 0110 0000 1010 ; R3 = 0x0032 (M[0x300B])
0010 0010 0000 1010 ; R1 = 0x5250 (M[0x300C])
0101 0100 1010 0000 ; Clear R2
0110 0000 0100 0000 ; R0 = M[R1]
0101 0000 0010 0001 ; R0 = R0 AND 0x0001
0000 0010 0000 0001 ; if P, goto x3007
0001 0100 1010 0001 ; R2 = R2 + 1
0001 0010 0110 0001 ; R1 = R1 + 1
0001 0110 1111 1111 ; R3 = R3 - 1
0000 0011 1111 1001 ; if P, goto x3003
1111 0000 0010 0101 ; HALT
0000 0000 0011 0010 ; 0x0032
0101 0010 0101 0000 ; 0x5250
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.
Sample Solution: