fall_06_e2 - ECE190 Exam 2, Fall 2006 Monday 30 October...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ECE190 Exam 2, Fall 2006 Monday 30 October Name: Be sure that your exam booklet has 13 pages. The exam is meant to be taken apart! Write your name at the top of each page. This is a closed book exam. You may not use a calculator. You are allowed TWO 8 . 5 11 " sheets of notes. Absolutely no interaction between students is allowed. Show all of your work. More challenging questions are marked with ***. Dont panic, and good luck! Adaptation of the a priori to the real world has no more originated from experience than adaptation of the fin of the fish to the properties of water. K. Lorenz, as quoted by N. Chomsky in Language and Mind , as quoted by O. Sacks in Seeing Voices Problem 1 20 points Problem 2 20 points Problem 3 20 points Problem 4 20 points Problem 5 20 points Total 100 points Name: 2 Problem 1 (20 points): Short Answers Please answer concisely. If you find yourself writing more than a few words or a simple drawing, your answer is probably wrong. Part A (5 points): Consider the following C function: void /* returns nothing */ func (int x) { switch ((5 < x) - (3 > x)) { case -1: printf ("Too cold \ n"); break; case 1: printf ("Too hot \ n"); break; case 0: printf ("Just right \ n"); break; default: printf ("Weird weather! \ n"); break; } } Fill in the blanks below to re-implement the function using if statements. void /* returns nothing */ func (int x) { if ( ) { printf ("Too cold \ n"); } else if ( ) { printf ("Too hot \ n"); } else if ( ) { printf ("Just right \ n"); } else { printf ("Weird weather! \ n"); } } Part B (5 points): Describe one advantage and one disadvantage of making a variable global rather than local to a certain function in a C program. Hint: the disadvantages outweigh the advantages in practice, particularly for large programs. Name: 3 Problem 1, continued: Part C (5 points): The C program below is intended to print the numbers from 10 down to 0 with one number per line. What does it actually do, and how could you fix it with one simple change? #include <stdio.h> int main () { int x; for (x = 10; 0 < x; --x) { printf ("%d \ n", x); } return 0; } Part D*** (5 points): Your friend is developing a magic 8-ball program for the LC-3. He shows you the following assembly code: LEA R1, SOURCE LEA R2, DEST LOOP LDR R0, R1, #0 STR R2, R0, #0 BRz DONE ADD R1, R1, #1 ADD R2, R2, #1 BRnzp LOOP DONE: LEA R0, DEST TRAP x22 ; PUTS TRAP x25 ; HALT SOURCE .STRINGZ " \ "My sources say no \ "" DEST .BLKW #20 MYDATA .FILL x0FFF Your friend complains that when he runs this code with his test cases, it never finishes executing (in other words, it never reaches the HALT trap). Explain why. (Note that the two-character sequence \ " inserts a single quotation mark, ASCII character x22, into a string.) Name: 4 Problem 2 (20 points): Systematic Decomposition to LC-3 Assembly 1 if printer is online 1 if printer is ready 15 14 13 unused PSR xFE80 PDR xFE82 15 unused 8 7 char to print wait for...
View Full Document

Page1 / 13

fall_06_e2 - ECE190 Exam 2, Fall 2006 Monday 30 October...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online