COMP 2121 Microprocessors and Interfacing Final Exam http

  • Slides: 15
Download presentation
COMP 2121: Microprocessors and Interfacing Final Exam http: //www. cse. unsw. edu. au/~cs 2121

COMP 2121: Microprocessors and Interfacing Final Exam http: //www. cse. unsw. edu. au/~cs 2121 Lecturer: Hui Wu Session 2, 2017

Final Exam • Fri 17/11/2011 13: 45, Centennial Room Randwick Racecourse. • 2 hours.

Final Exam • Fri 17/11/2011 13: 45, Centennial Room Randwick Racecourse. • 2 hours. • Closed book. • 60% of the final marks. 2

Scope of Final Exam Topics not examinable: • • Introduction to digital circuits Floating

Scope of Final Exam Topics not examinable: • • Introduction to digital circuits Floating point numbers Serial input and output Analog input and output 3

Structure of Final Exam Two Parts: • Part I: Basic Concepts (50 marks) q

Structure of Final Exam Two Parts: • Part I: Basic Concepts (50 marks) q 6 questions. • Part II: AVR Assembly Programming (50 marks) q 3 questions v First one compulsory v Do either the second or the third 4

Sample Questions of Part I (1/8) Consider the following program: ldi r 0, 1

Sample Questions of Part I (1/8) Consider the following program: ldi r 0, 1 clr r 2 clr r 3 loop: cpi r 0, 201 breq end add r 2, r 0 adc r 3, r 1 inc r 0 jmp loop end: nop 5

Sample Questions of Part I (2/8) If the program is executed on an AVR

Sample Questions of Part I (2/8) If the program is executed on an AVR microcontroller with a clock frequency of 8 MHz, what is its execution time? 6

Sample Questions of Part I (3/8) Consider the following AVR assembly code. ldi r

Sample Questions of Part I (3/8) Consider the following AVR assembly code. ldi r 10, low(-1) ldi r 11, high(-1) ldi r 20, low(0 x 500) ldi r 21, high(0 x 500) cp r 10, r 20 cpc r 11, r 21 brge comp 2121 clr r 16 rjmp end comp 2121: ldi r 16, 1 end: nop 7

Sample Questions of Part I (4/8) Assume that the address of the instruction “

Sample Questions of Part I (4/8) Assume that the address of the instruction “ ldi r 10, low(-1)” is 0 x 0202. After the above sequence of code is executed, what are the contents in r 10, r 11, r 20, r 21 and r 16, respectively? 8

Sample Questions of Part I (5/8) A C program consists of five functions. Their

Sample Questions of Part I (5/8) 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) { … func 1(…); func 2(…); … } 9

Sample Questions of Part I (6/8) int func 1(…) { … func 1(…); …

Sample Questions of Part I (6/8) int func 1(…) { … func 1(…); … } int func 2(…) { … func 3(…); func 4(…); … } 10

Sample Questions of Part I (7/8) func 1() is a recursive function and calls

Sample Questions of Part I (7/8) func 1() is a recursive function and calls itself 15 times for the actual parameters given in main(). Both func 3() and func 4() do not call any function. The sizes of all stack frames are shown as follows. main(): 200 bytes. func 1(): 100 bytes. func 2(): 400 bytes. func 3(): 1, 400 bytes func 4(): 300 bytes How much stack space is needed to execute this program correctly? 11

Sample Questions of Part I (8/8) Consider the following keypad design for a toy.

Sample Questions of Part I (8/8) Consider the following keypad design for a toy. The keypad has only two keys. 10 symbols 0, 1, …, 9 need to be generated via the two keys. Give an encoding scheme such that the 10 symbols can be generated via the two keys, and explain how each symbol is generated. 12

Sample Questions of Part II (1/3) Write an AVR assembly program to find the

Sample Questions of Part II (1/3) Write an AVR assembly program to find the maximum value of a one-dimensional integer array A. Assume that the array A has 30 elements and each element is 2 -byte long. Your program must store the array A in the data memory. Assume that A has been initialized. Therefore, your program does not need to initialize it. 13

Sample Questions of Part II (2/3) Write an AVR assembly program to implement the

Sample Questions of Part II (2/3) 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; } 14

Sample Questions of Part II (3/3) int sum(int n) { if (n<=0) return 0;

Sample Questions of Part II (3/3) 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. 15