Single Instruction - Introduction to Engineering - Previous Exam, Exams of Biomedical Engineering

Main points of this past exam are: Single Instruction, Equivalent, Program, Supposed, Character Input, Wrong, Making a Single Change

Typology: Exams

2012/2013

Uploaded on 04/01/2013

nishaa
nishaa 🇮🇳

4.3

(13)

56 documents

1 / 12

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
ECE 199 Exam 2 Fall 2003
Tuesday, November 4th, 2003
Name:
Be sure your exam booklet has 12 pages.
Write your name at the top of each page.
This is a closed book exam.
You are allowed one 8.5 x 11 sheet of notes.
Absolutely no interaction between students is allowed.
Show all of your work.
Challenge questions are marked with a ***
Don’t panic, and good luck!
Problem 1 20 points
Problem 2 20 points
Problem 3 20 points
Problem 4 20 points
Problem 5 20 points
Total 100 points
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Single Instruction - Introduction to Engineering - Previous Exam and more Exams Biomedical Engineering in PDF only on Docsity!

ECE 199 Exam 2 Fall 2003

Tuesday, November 4th, 2003

Name:

• Be sure your exam booklet has 12 pages.

  • Write your name at the top of each page.
  • This is a closed book exam.
  • You are allowed one 8.5 x 11 sheet of notes.
  • Absolutely no interaction between students is allowed.
  • Show all of your work.
  • **Challenge questions are marked with a *****
  • Don’t panic, and good luck!

Problem 1 20 points

Problem 2 20 points

Problem 3 20 points

Problem 4 20 points

Problem 5 20 points

Total 100 points

Problem 1 (20 points): Short Answer

Part A (4 points): What single instruction is equivalent to the following two LC-3 instructions? LEA R7, # JMP R Part B (6 points): The following LC-3 program is supposed to ask the user for a character input and output that character in quotes. However, it has a bug. BRIEFLY describe what is wrong and then fix the bug by making a single change. .ORIG x LEA R0, PROMPT PUTS GETC OUT STI R0, DATA LEA R0, OUTPUT PUTS HALT PROMPT .STRINGZ "Enter a character: " OUTPUT .FILL x0A ; The ASCII Line Feed character .FILL x22 ; The ASCII quote character (") DATA .FILL x22 ; Overwrite with key press .FILL x .FILL x .END

Problem 2 (20 Points): I/O and Stacks in LC-

Part A (10 points): Many devices require that a processor attend to their needs within a certain amount of time. A typical keyboard, for example, does not have much storage of its own and cannot keep track of sequences of typed characters, only single keystrokes. If polling I/O is used, and the processor (for whatever reason) does not check for keyboard input during a period in which two or more keys are pressed, some of the keystrokes are lost. In this problem, you will address this issue by changing the GETC trap handler to make the monitor beep by sending an ASCII BEL character to the display whenever keystrokes are lost. To support your extension, assume that the KBSR contains an OVERFLOW bit (bit 0, with value 1) to indicate the loss of keystrokes to you. The OVERFLOW bit is set whenever the processor fails to read KBDR between two keystrokes, and is cleared after KBSR is read. Things you may find useful: the display status register (DSR) is mapped at address xFE04; the display data register (DDR) is mapped at address xFE06; the ASCII code for BEL (bell, or beep) is 7. Keep in mind that registers other than R0 are callee-saved ( i.e. , you must save them). .ORIG x GETC LDI R0,KBSR ; wait for a keystroke; note that BRzp GETC ; overflow can’t occur without one ; a. your new code goes here (write it below) GET_KEY LDI R0,KBDR ; read the last keystroke RET ; and return it KBSR .FILL xFE00 ; keyboard status register address KBDR .FILL xFE02 ; keyboard data register address ; b. also indicate any new data/storage that you need (which go here) .END a. b.

Problem 2, continued:

Part B (10 points): Use stacks to help you write a short LC-3 program to print out a list of strings in reverse. The strings are stored in memory exactly as in MP2: beginning at x5005, NUL terminated, and with an additional terminating NUL indicating the end of the list. There may be zero or more strings. You must print all strings in the reverse order that they were found; there is no error checking on the number of strings. Follow each string with a linefeed character (0x0A). You must make use of the three provided subroutines, whose semantics are described below. Assume they are already written for you and use the callee save convention. Also assume the stack is initially empty. FIND_NUL – Locates the first NUL in memory, beginning from the passed in address. Inputs: R0 – The address to begin looking for the next NUL character. Outputs: R0 – Unchanged. R1 – The address of the character past the first NUL found. R5 – Set to 1 if R0 pointed to a NUL character, 0 else. POP – Pops the top of the stack and returns it. Inputs: None Outputs: R0 – The data from the top of the stack. R5 – 1 if underflow occurred, 0 else. PUSH – Pushes data onto the top of the stack. Inputs: R0 – The data to be pushed. Outputs: None ( You may assume overflow will not occur .) .ORIG x

Problem 3, continued:

Part A (12 points): Which LC-3 instructions correspond to (give the instruction numbers shown in the comments): a. The initialization of the for loop? b. The test (middle part) of the for loop? c. The update (re-initialization) of the for loop? Part B (6 points): Using the LC-3 translation of Foo, write the body of the for loop here.

***Part C (2 points): What is the return value of a relative to the value of a passed into Foo?

Problem 4 (20 Points): C Control Flow

Part A (8 points): Fill in the blank below so that the program executes the code in the if statement as specified. if (_________________________________________________) { /* Execute this block of code if the

  • integer variable x is a multiple
  • of 5 whose absolute value is
  • greater than 100 / / Code / } Part B (12 points): Rewrite the below function to use exactly one return statement. You do not have to rewrite the comments. int PosDiv( int a, int b ) { / ‘a’ and ‘b’ are some arbitrary user supplied integers. / if( b == 0 ) { return –1; / Error 1: Don’t divide by zero / } if( ( a < 0 ) || ( b < 0 ) ) { return –2; / Error 2: Positive numbers only */ } return a / b; }

Part B (8 points): Now assume the program is written with your work in Part A being placed into a function called PlayRound. This function will play only a single round of the game. Give the declaration of PlayRound and show how it would be called. Explain your reasoning for this declaration. Note: Assume no variables are global.

Scratch Paper for Calculations