DOC PREVIEW
UW-Madison CS/ECE 252 - CS/ECE 252 Midterm Examination 3

This preview shows page 1-2-3-4 out of 11 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERINGCOMPUTER SCIENCES DEPARTMENTUNIVERSITY OF WISCONSIN-MADISONProf. David A. WoodTAs Spyros Blanas, Priyananda Shenoy, Shengnan Wang Midterm Examination 3In Class (50 minutes)Monday, April 21, 2008Weight: 15%CLOSED BOOK, NOTE, CALCULATOR, PHONE, & COMPUTER.The exam is two-sided and has 10 pages, including two blank pages and a copy of the LC-3 Instruction Set handout on the final page (please feel free to detach this final page, but insert it into your exam when you turn it in).You are required to present a valid UW-Madison student ID card or other government-issued photo ID to one of the teaching assistants who are proctoring this exam before leaving the room. If you fail to do so, we cannot grade your exam.Plan your time carefully, since some problems are longer than others.NAME: __________________________________________________________ID# ______________________________________________________________1ProblemNumberMaximumPointsPointsAwarded1 122 93 154 245 206 107 10Total 100Problem 1 (12 points)The following LC-3 program has been loaded into memory: Address Instructionx5000 1001 0010 0011 1111x5001 0001 0010 0110 0001x5002 0001 0010 0100 0010x5003 0000 0110 0000 0110a) The contents of the registers are shown below:R0 is 4 R1 is 3 R2 is 0 R3 is 5Which condition codes are set and what is the value of the PC after instruction at x5003 is executed?b) The contents of the registers are shown below:R0 is 3 R1 is 0 R2 is 5 R3 is 4Which condition codes are set and what is the value of the PC after instruction at x5003 is executed?3Problem 2 (9 points)The contents of the memory and the registers are shown below:Register Value Memory address ValueR0 x3012 x3010 x3012R1 x002A x3011 x3010R2 x300B x3012 xBEEFWe start executing from address x3000. What 's the value in R1 after each instruction is executed?a) If x3000 is 0010 0010 0001 0000 LD R1, PTRb) If x3000 is 0110 0010 1000 0111 LDR R1, 7(R2)c) If x3000 is 1010 0010 0001 0000 LDI R1, PTRProblem 3 (15 points)The program below sums a sequence of numbers. The address to the start of the sequence is stored in R2 and the number of elements in that sequence is stored in R3. Insert the missing LC-3 machine language instructions. Adding comments to each machine language instruction will assist in awarding partial credit. Address Instructionx5000 0101 1111 1110 0000 ; AND R7,R7,#0x5001 0110 0010 1000 0000 ; LDR R1,R2,#0 x5002 0001 1111 1100 0001 ; ADD R7,R7,R1x5003 x5004 0001 0110 1111 1111 ; ADD R3,R3,#-1x5005x5006 1111 0000 0010 0101 ; HALT5Problem 4 (24 points)There is something wrong with the following code. This code is supposed to count the number of positive numbers in a sequence, save this number in R7 and then exit. The sequence always has 10 elements and the address of the start of the sequence has been stored in register R2.Address Instructionx3005 0101 0000 0010 0000 ; AND R0, R0, #0x3006 0001 0000 0010 1010 ; ADD R0, R0, #10x3007 0101 1111 1110 0000 ; AND R7, R7, #0x3008 0110 0010 1000 0000 ; LDR R1, R2, #0x3009 0000 0010 0000 0001 ; BRp #1x300A 0001 1111 1110 0001 ; ADD R7, R7, #1x300B 0001 0100 1010 0001 ; ADD R2, R2, #1x300C 0001 0000 0011 1111 ; ADD R0, R0, #-1x300D 0000 0011 1111 1010 ; BRp #-6x300E 1111 0000 0010 0101 ; HALTExplain what happens when we try to execute this code. Comments are provided to save you the effort of decoding the machine language.If you had a debugger, briefly describe how you would use it to debug this program.Problem 5 (20 points)The current state of the memory is given below: Memory AddressMemory Contentsx3006 xABCDxABCD x1220x2FFF x4567x1220 x9876xABDB x0001x30F3 x0020x200E x3258x3258 x0000x300E x92FEx3005 x200EWe load and execute the following program:Address Instructionx3000 1010 0000 0000 0101x3001 0110 0110 0000 0000 ; LDR R3, R0, x0x3002 1110 0010 1111 0000 x3003 0010 0101 1111 1110 ; LD R2, x1FEx3004 1111 0000 0010 0101What will be the final contents of registers R0-R3 when we reach the HALT instruction? Write your answers in hexadecimal format.Register Initial contents Final contentsR0 x200ER1 x200ER2 x3001R3 x30017Problem 6 (10 points)If the value stored in R0 is 1 at the end of the execution of the following instructions, what can be inferred about R3?Address Instructionx4000 1110 0011 1111 1111x4001 0101 0000 0010 0000 AND R0, R0, x0x4002 0001 0100 0100 0001x4003 0101 0110 1000 0011x4004 0000 0100 0000 0001x4005 0001 0000 0010 0001 ADD R0, R0, x1a. R3 is negativeb. R3 is positivec. R3 is equal to 0d. R3 is zero or positiveProblem 7 (10 points)What does the following instruction sequence do?Address Instructionx4000 1110 0000 0001 0000x4001 1100 0000 0000 0000Can you do the same using a single instruction only? If yes, which one? If no, why?Scratch Sheet 1 (in case you need additional space for some of your answers)9Scratch Sheet 2 (in case you need additional space for some of your answers)LC-3 Instruction Set (Entered by Mark D. Hill on 03/14/2007; last update 03/15/2007)PC’: incremented PC. setcc(): set condition codes N, Z, and P. mem[A]:memory contents at address A.SEXT(immediate): sign-extend immediate to 16 bits. ZEXT(immediate): zero-extend immediate to 16 bits.Page 2 has an ASCII character table. 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ ADD DR, SR1, SR2 ; Addition| 0 0 0 1 | DR | SR1 | 0 | 0 0 | SR2 | +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ DR ß SR1 + SR2 also setcc()+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ ADD DR, SR1, imm5 ; Addition with Immediate| 0 0 0 1 | DR | SR1 | 1 | imm5 | +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ DR ß SR1 + SEXT(imm5) also setcc()+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ AND DR, SR1, SR2 ; Bit-wise AND| 0 1 0 1 | DR | SR1 | 0 | 0 0 | SR2 | +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ DR ß SR1 AND SR2 also setcc()+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ AND DR, SR1, imm5 ; Bit-wise AND with Immediate| 0 1 0 1 | DR | SR1 | 1 | imm5 | +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ DR ß SR1 AND SEXT(imm5) also setcc()+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ BRx, label (where x = {n,z,p,zp,np,nz,nzp}) ;


View Full Document
Download CS/ECE 252 Midterm Examination 3
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view CS/ECE 252 Midterm Examination 3 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view CS/ECE 252 Midterm Examination 3 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?