Sie sind auf Seite 1von 8

Initials: ________

CprE 211 Spring 2007 Exam 1


Last Name (printed) First Name (printed) Lab Section ISU Email ID _________________________ _________________________ _________________________ _________________________

Instructions: Do not open this exam booklet until told to do so. Closed book. Closed notes. Calculator NOT allowed. One-page, double-sided help sheet allowed. Be prepared to show this sheet to the instructor or submit it with your exam packet. Do all work in the space provided. You must show your work to receive credit. Clearly indicate the answer you want counted. Make assumptions if necessary to work problems. Be sure to complete the five lines above. Cheating will not be tolerated by the instructor or your classmates and will result in a severe penalty. This is a 75-minute exam. Question 1 2 3 4 Total Points Possible 10 15 20 15 60 Points

NOTE: Unless specified otherwise, you should assume that for questions involving C or assembly code, the target is the MPC555 used in the lab.

Initials: ________

All questions in parts II, III and IV are regarding the MPC555 processor, which is 32-bit and by default big-endian.

I. [10] Number System


You are given a sequence of bits: 10110111. Answer the following questions. 1. [2] Convert this sequence of bits to a hexadecimal number.

2. [2] Convert this sequence of bits to an octal number.

3. [3] What is the unsigned decimal value of this sequence of bits?

4. [3] What is the signed decimal value of this sequence of bits? Assume 2s complement is used.

Initials: ________

II. C Programming Language (15 points)


You must use a good programming style, e.g. meaningful variable names, appropriate comment and consistent indentation. 1. [10] Write a function checksum that calculates the checksum of an integer array of given length. The checksum is the XORed valued of all array elements. There are two input parameters, the array address of type int * and the number of element of type int. The return value is the checksum of all array elements of type int. a. [2] Write the prototype of the function.

b. [5] Implement the function body using a for loop. You only need to write the function body.

c. [3] Implement the function body using a while loop. You only need to write the function body.

Initials: ________

2. [3] The following function is supposed to calculate the absolute value of an integer. int abs(int x) { if (x > y); return x; return y; } Does the function work correctly? Explain.

3. [2] Consider the following statements. unsigned a = 0xffffffff; int b = 0xffffffff; a = (a >> 4); b = (b >> 4); What are the values of a and b at the end of the program?

Initials: ________

III. Embedded Programming in C (20 points)


For questions 1-4, consider the following C code fragment that reads the input from a DIP switch. unsigned char dip_input = *(unsigned char *) (IO_DIGITAL_INPUT_DIP_1); 1. [3] Write a C if condition to test if bits 7, 6, 4 and 3 are all set.

2. [2] Write a C if condition to test if bit 7, 6, 1, or 0 is set.

3. [3] Write a C if condition to test if any of bits 7, 5, 2, or 0 is NOT set.

4. [4] Write a C statement to swap bits 7-5 and bits 2-0 of dip_input. (The value should be written back into the variable.)

Initials: ________

5. [8] Assume the DIP switch input is interpreted as follows: Bits 7-5 3-bit integer 1 Bits 4-2 3-bit integer 2 Bit 1 not used Bit 0 valid bit 1 if valid, 0 if not valid The following is a function template that reads and parses the DIP input. If the input is valid, the function returns 1 and passes the two 3-bit integers through the two pointers pByte1 and pByte2; otherwise, the return value is 0. Complete the function. /* reads and parses the DIP input */ int read_dip(unsigned char *pByte1, unsigned char *pByte2) { unsigned char dip_input = *(unsigned char *) (IO_DIGITAL_INPUT_DIP_1);

Initials: ________

IV. [15] Data Memory Layout


Consider the following memory dump and variable declarations and answer the questions. Assume that the first variable is in memory starting at the starting address of the memory dump. Assume Big-Endian byte-ordering and remember to consider byte-alignment rules for different data types.
Address

10001FF0 10001FF8 10002000 10002008 10002010

Memory Contents

AA 33 10 13 01

BB 44 00 42 92

CC 55 20 35 83

DD 66 10 64 74

EE 10 56 57 65

FF 00 67 86 56

11 20 78 79 47

22 10 89 08 38

short a; int b; char c; int* d; short e[5]; a. [2] What is the address of c? _________________ b. [2] What is the hexadecimal value of b? ___________________ a. [2] What is the hexadecimal value of *d? ___________________ d. [3] What is the hexadecimal value of *(d+1)? ________________ e. [4] Re-arrange the variable declarations so that the minimum space is wasted due to byte-border constraints.

Initials: ________

f. [2] How much space (in bytes) was saved by performing the re-arrangement in part e?

Das könnte Ihnen auch gefallen