24
COMP3221: Microprocessors and Embedded Systems Final Exam http:// www.cse.unsw.edu.au/~cs3221 Lecturer: Hui Wu Session 1, 2005

COMP3221: Microprocessors and Embedded Systems Final Exam cs3221 Lecturer: Hui Wu Session 1, 2005

  • View
    234

  • Download
    5

Embed Size (px)

Citation preview

Page 1: COMP3221: Microprocessors and Embedded Systems Final Exam cs3221 Lecturer: Hui Wu Session 1, 2005

COMP3221: Microprocessors and Embedded Systems

Final Exam

http://www.cse.unsw.edu.au/~cs3221

Lecturer: Hui Wu

Session 1, 2005

Page 2: COMP3221: Microprocessors and Embedded Systems Final Exam cs3221 Lecturer: Hui Wu Session 1, 2005

COMP3221/9221: Microprocessors and Embedded Systems

2

Final Exam

• 3 hours.

• Open book. No calculator is allowed.

• 50% of the total marks. Lab: 25% Assignment1: 10% Assignment 2: 15%

• Different exam papers for undergraduate and postgraduate students.

Page 3: COMP3221: Microprocessors and Embedded Systems Final Exam cs3221 Lecturer: Hui Wu Session 1, 2005

COMP3221/9221: Microprocessors and Embedded Systems

3

Scope of Final Exam

Topics Covered:

• All topics, excluding Serial Communication and Memory Systems.

Page 4: COMP3221: Microprocessors and Embedded Systems Final Exam cs3221 Lecturer: Hui Wu Session 1, 2005

COMP3221/9221: Microprocessors and Embedded Systems

4

Structure of Final Exam

Four Questions:

• Question 1: Basic Concepts (20 marks) 10 PARTs.

• Question 2: Miscellaneous Questions (20 marks) 7 PARTs.

• Question 3: AVR Assembly Programming (30 marks) 3 PARTs.

• Question 4: Interrupts and I/O (30 marks) 7 PARTs.

Page 5: COMP3221: Microprocessors and Embedded Systems Final Exam cs3221 Lecturer: Hui Wu Session 1, 2005

COMP3221/9221: Microprocessors and Embedded Systems

5

Sample PARTs in Question 1

Discuss the advantages of using macros versus functions. (2 marks)

Page 6: COMP3221: Microprocessors and Embedded Systems Final Exam cs3221 Lecturer: Hui Wu Session 1, 2005

COMP3221/9221: Microprocessors and Embedded Systems

6

Sample PARTs in Question 1 (Cont.)

Describe how the prioritisation is achieved in daisy chain interrupts. (2 marks)

Page 7: COMP3221: Microprocessors and Embedded Systems Final Exam cs3221 Lecturer: Hui Wu Session 1, 2005

COMP3221/9221: Microprocessors and Embedded Systems

7

Sample PARTs in Question 2

Consider a two dimensional integer array A, where the array element A[x,y] is at row x (x 0) and column y (y 0). A is stored at 0x0200 in memory and has 100 rows and 50 columns. The size of each element is eight bytes. Assume that array A is stored in memory in row-major order i.e. in sequential order; the elements of row 0 first, row 1 second and so on. Give a formula for computing the address of the element A[i,j] (0 i 99 and 0 j 49). (3 marks)

Page 8: COMP3221: Microprocessors and Embedded Systems Final Exam cs3221 Lecturer: Hui Wu Session 1, 2005

COMP3221/9221: Microprocessors and Embedded Systems

8

Sample PARTs in Question 2 (Cont.)

Consider two single precision floating point numbers x and y in IEEE 754 format, where x=0xC0EE8000 and y=0xC1AA4000. What is the hexadecimal value of the result of x+y in IEEE 754 format? (3 marks)

Page 9: COMP3221: Microprocessors and Embedded Systems Final Exam cs3221 Lecturer: Hui Wu Session 1, 2005

9

Sample PARTs in Question 2 (Cont.)

Consider the following AVR assembly code.  .set x=pc ldi r20, low(x) ldi r21, high(x) ldi r30, low(pc) ldi r31, high(pc)

Assume that the address of the instruction “ ldi r20, low(x)” is 0x0202. After the above sequence of code is executed, what are the contents in r20, r21, r30, and r31, respectively? (3 marks)

Page 10: COMP3221: Microprocessors and Embedded Systems Final Exam cs3221 Lecturer: Hui Wu Session 1, 2005

10

Sample PARTs in Question 2 (Cont.)

A C program consists of five functions. Their calling relations are shown as follows (the arguments and irrelevant C statements are omitted).

int main(void) { … func1(…); func2(…); … }

Page 11: COMP3221: Microprocessors and Embedded Systems Final Exam cs3221 Lecturer: Hui Wu Session 1, 2005

11

Sample PARTs in Question 2 (Cont.)

int func1(…) { … func1(…); … } int func2(…) { … func3(…); func4(…); … }

Page 12: COMP3221: Microprocessors and Embedded Systems Final Exam cs3221 Lecturer: Hui Wu Session 1, 2005

12

Sample PARTs in Question 2 (Cont.)

func1() is a recursive function and calls itself 15 times for the actual parameters given in main(). Both func3() and func4() do not call any function. The sizes of all stack frames are shown as follows.

main(): 200 bytes. func1(): 100 bytes. func2(): 400 bytes. func3(): 1,400 bytes func4(): 300 bytes

Draw the call tree of this program. (2 marks)

How much stack space is needed to execute this program correctly? (3 marks)

Page 13: COMP3221: Microprocessors and Embedded Systems Final Exam cs3221 Lecturer: Hui Wu Session 1, 2005

COMP3221/9221: Microprocessors and Embedded Systems

13

Sample PARTs in Question 3

Write an AVR assembly program to find the minimum value of all array elements in the one-dimensional integer array A. Your program must satisfy the following requirements.• Array A has 10 elements and each element is a 2-byte signed integer.• Each element A[i] (i=0, 1, …, 9) has an initial value that is stored in the flash memory. You may choose any integer value for each element.• Array A is stored contiguously in the SRAM.• Your program must define and use at lease one MACRO.• The minimum value found by your program is stored in registers r26:r25. (10 marks)

Page 14: COMP3221: Microprocessors and Embedded Systems Final Exam cs3221 Lecturer: Hui Wu Session 1, 2005

COMP3221/9221: Microprocessors and Embedded Systems

14

Sample PARTs in Question 3 (Cont.)

Consider an embedded system using an AVR Mega64 microcontroller. Assume that Timer/Counter 0 Overflow Interrupt has been set to occur every 200 ms in the main program. Write an interrupt service routine ISR0 for Timer/Counter 0 Overflow Interrupt to count the number of hours that has passed since the embedded system started to operate. (10 marks)

Page 15: COMP3221: Microprocessors and Embedded Systems Final Exam cs3221 Lecturer: Hui Wu Session 1, 2005

15

Sample PARTs in Question 3 (Cont.)

Write an AVR assembly program to implement the following C program.

int sum(int n);

int main(void)

{ int n=100;

sum(n);

return 0;

}

Page 16: COMP3221: Microprocessors and Embedded Systems Final Exam cs3221 Lecturer: Hui Wu Session 1, 2005

16

Sample PARTs in Question 3 (Cont.)

int sum(int n)

{ if (n<=0) return 0;

else return (n+ sum(n-1));

}

All local variables and parameters must be stored in the stack space. You need to choose a proper size for n and describe the stack frame structure using a diagram. (10 marks)

Page 17: COMP3221: Microprocessors and Embedded Systems Final Exam cs3221 Lecturer: Hui Wu Session 1, 2005

17

Sample PARTs in Question 4

Assume for a processor with a 700 MHz clock it takes 150 clock cycles for a polling operation (calling polling routine, accessing the device, and returning). The overhead for an interrupt operation is 200 clock cycles. Hard disk transfers data in 128-byte chunks and can transfer at 6 M bytes/second rate.

If the processor uses software polling, what percentage of the processor time is tied up in polling the hard disk to achieve a data transfer rate of 6M bytes/second? (4 marks)

Page 18: COMP3221: Microprocessors and Embedded Systems Final Exam cs3221 Lecturer: Hui Wu Session 1, 2005

18

Sample PARTs in Question 4 (Cont.)

If the processor uses interrupt technique and the interrupt rate is equal to software polling rate, what percentage of the processor time is tied up in servicing interrupt by the hard disk during the data transfer? (4 marks)

Page 19: COMP3221: Microprocessors and Embedded Systems Final Exam cs3221 Lecturer: Hui Wu Session 1, 2005

19

Sample PARTs in Question 4 (Cont.)

Consider an embedded system using an AVR mega64 microcontroller. There are 5 interrupting sources, Int0, Int1, …, Int4. The size of the stack space needed by each interrupt service routine, denoted also by Inti (i=0, 1, …, 4) for simplicity, is shown as follows.

Int0: 100 bytes

Int1: 50 bytes

Int2: 20 bytes

Int3: 40 bytes

Int4: 50 bytes

If no interrupt occurs, the correct execution of the program needs 1K bytes of stack space in the worst case.

Page 20: COMP3221: Microprocessors and Embedded Systems Final Exam cs3221 Lecturer: Hui Wu Session 1, 2005

20

Sample PARTs in Question 4 (Cont.)

If interrupts may occur at any time and each interrupt service routine does not enable the Global Interrupt Flag I in the Program Status Register, how much stack space is needed by the program in the worst case? (4 marks)

Page 21: COMP3221: Microprocessors and Embedded Systems Final Exam cs3221 Lecturer: Hui Wu Session 1, 2005

21

Sample PARTs in Question 4 (Cont.)

Assume that an interrupting device generates a new interrupt request only if its last interrupt request has been processed i.e. its interrupt service routine has been finished. If interrupts may occur at any time and each interrupt service routine enables the Global Interrupt Flag I in the Program Status Register at the beginning of the interrupt service routine, how much stack space is needed by program in the worst case? (4 marks)

Page 22: COMP3221: Microprocessors and Embedded Systems Final Exam cs3221 Lecturer: Hui Wu Session 1, 2005

22

Sample PARTs in Question 4 (Cont.)

Consider designing an electronic toy. It uses a 2*2 keypad to get the input from the user and requires that any decimal integer number and four directions (up, down, left and right) be input via 4 keys. If a straightforward key scanning approach like the one in our Lab 4 is used, only 4 symbols can be input to the electronic toy, which does not satisfy the requirement.

Page 23: COMP3221: Microprocessors and Embedded Systems Final Exam cs3221 Lecturer: Hui Wu Session 1, 2005

23

Sample PARTs in Question 4 (Cont.)

Design an encoding scheme such that all the required symbols can be represented via 4 keys. (4 marks)

Page 24: COMP3221: Microprocessors and Embedded Systems Final Exam cs3221 Lecturer: Hui Wu Session 1, 2005

24

Sample PARTs in Question 4 (Cont.)

Describe a key scanning procedure which implements your encoding scheme using a diagram or an algorithm. (6 marks)