Beruflich Dokumente
Kultur Dokumente
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.
4. [3] What is the signed decimal value of this sequence of bits? Assume 2s complement is used.
Initials: ________
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: ________
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: ________
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?