You are on page 1of 13

School of Engineering

Department of Computer and Communications Engineering


Spring 2017-2018

CENG380 – Microprocessors and microcontrollers


Instructors: Prof. Amin Haj-Ali, Dr. Abbas El Mostrah, Dr. Abdel Mehsen Ahmad
Dr. Ali Bazzi , Dr. Ali Haroun, Dr. Ali Kalakech, Dr. Hussein Hijazi
Dr. Ibrahim El Bitar, Dr. Mohamad Najem, Dr. Oussama Tahan
Dr. Zaher Merhi

Date: Tuesday March 27, 2018


Time: 17:00-18:15

Student Name: ______________________ ID: ______________________Section: __________

Instructions:
• Closed book/notes
• Calculators allowed
• Answer all questions
• Total pages: 15 including cover (15 Question sheets + 3 PIC Instruction set
sheets)

Question Mark Weight


1 16
2 14
3 40
4 30
Total 100

Page 1 of 13
Question 1: General architectures questions (16 points)

a. Explain the difference between Harvard and Von-Neumann


architectures (4 points)

Harvard: program rom and data ram are separated, each one has its
own data bus and address bus

Von Neumann: Program ROM and Data RAM shares the same buses

2 points for each

b. What is the difference between RAM and ROM and why we store the
programs in the ROM? (4 points)

RAM is volatile, we loose data when the power is turned off so it is


used to store temp. data
ROM is non volatile the data is not lost when the power is turned off so
here we store the program
2 points each

c. Suppose we have a computer with 16 data lines and 16 address lines.


What is the effect of the data lines and what is the maximum supported
memory? (4 points)

16 data lines: we can load or store 16 bits at the same time


maximum supported memory is 2address lines 2Bytes = 128Kbytes
2 points each

Page 2 of 13
d. An AVR has 0x1FFF as the address of its last byte of its ROM. What is
the size of the ROM? (4 points)

We have 213 location = 8K location (2 points)


In the AVR ROM each location is 2 bytes so 16 Kbytes (2 points)

Page 3 of 13
Question 2: CALL and the stack (14 points)
Consider the following AVR assembly program. Suppose that the stack is initialized at the
end of the RAM.

.org 0x00
JMP main

.org 0x200
main:
LDI R16, 100
LDI R17, 0
DEC R16
CALL sub1
CALL sub2

.org 0x320
sub1:
DEC R16
CALL sub2
RET

.org 0x400
sub2:
CALL sub3
RET

.org 0x600
sub3:
DEC R16
RET

a) What would be the contents of the stack when the program reaches sub2 for the first time?
(4 points)

23
STACK =
03
00
05
02
00

Page 4 of 13
b) What would be the contents of the stack when the program reaches sub2 for the second time?
(4 points)

STACK
23
03
00

c) Would the program generate a stack overflow or a stack underflow?


(3 points)

no stack overflow nor underflow

d) What is the value of R16 at the end? (3 points)

96

Page 5 of 13
Question 3: AVR assembly language (40 points)

Part1: Translation to binary (14 points)


Translate the following program into its machine code values (in Hexadecimal). Fill all the
information in the table below to reflect the content of the program memory.

.org 0x100
main
LDI R16, 10
LDI R17, 5
Loop: call sub1
DEC R16
BRNE Loop

.org 0x160
sub1:
INC R17
RET

Address Instruction In binary In hex


0x0100 LDI R16, 10 1110 0000 0000 1010 0xE00A

1 point
LDI R17, 5 (2 points)

1 point
CALL sub1 (3 points)

1 point
DEC R16 1001 0101 0000 1010 0x950A

1 point
BRNE loop (3 points)

0x160 INC R17 1001 0101 0001 0011 0x9513

1 point
RET (1 point)

Page 6 of 13
Solution

Address Instruction In binary In hex


0x0100 LDI R16, 10 1110 0000 0000 1010 0xE00A

1 point
0x101 LDI R17, 5 1110 0000 0001 0101 0xE015 (2 points)

1 point
1001 0100 0000 1110 0x940E
0x102 CALL sub1 (3 points)
0000 0001 0110 0000 0x0160

1 point
0x104 DEC R16 1001 0101 0000 1010 0x950A

1 point
0x105 BRNE loop 1111 0111 1110 0101 0xF7E5 (3 points)

0x160 INC R17 1001 0101 0001 0011 0x9513

1 point
0x161 RET 1001 0101 0000 1000 0x9508 (1 point)

Page 7 of 13
Part2: Program Tracing (15 points)

a. What are the values of R16 and the carry after the following sequence of
instructions? (5 points)
CLC
LDI R16, 0xF4
ROR R16
ROR R16
ROR R16

Solution R16=0x1E and C=1

b. What is the contents of R0 after performing the following sequence of


instructions (5 points)
LDI R16, 3
LDI R17, 4
MUL R17, R16
INC R0

0x0D

c. What is the value of the Z flag after executing these lines of code? (5 points)

LDI R21, 0
INC R21
LDI R21, 0

0 because LDI does not affect the flag, last result that affect the flag is 1 obtained
from INC

Page 8 of 13
Part3: General Assembly programming (11 points)

a. When we need to load the value of PINA into R4, the fastest way is to write:
IN R4, PINA
What is the alternative way using LDS? (N.B. you can use the datasheet at the
end of your exam booklet to find the I/O memory mapping)
(4 points)

Solution
LDS R4, 0x39 0 grade for LDS, R4, 0x19

b. We need to write an assembly program to multiply by 4 the contents of the RAM


location 0x400. Then the result will be stored in memory locations 0x401 (higher
byte) and 0x402 (lower byte). Fill the blank (7 points)

.org 0x00
____ R20, 0x400 1 point
LDI R21, _______ 1 point
_____ R20, R21 1 point
_____ _____, _____ 2 points
_____ ______, ______ 2 points

solution
.org 0x00
LDS R20, 0x400 1 point
LDI R21, 4 1 point
MUL R20, R21 1 point
STS 0x401, R1 2 points
STS 0x402, R0 2 points

Page 9 of 13
Question 4 Multiple choices (30 points)

This question covers all the chapters included for the exam.
Select the one correct answer according to your best knowledge.
Each correct answer earns 2 or 3 points.

1) After performing the following code: (3 points)


LDI R16, 0x49
LDI R17, 0xB7
ADD R17, R16
a) Z=0, N=0, H=0, C=1, V=0
b) Z=1, N=0, H=1, C=1, V=0
c) Z=0, N=0, H=0, C=1, V=1
d) Z=1, N=1, H=1, C=0, V=1

2) What is the size of the following program in the program ROM? (3 points)
.org 0x00
LDI R20, 5
LDI R21, 6
loop DEC R21
JMP loop
nop
a) 5 Bytes
b) 6 Bytes
c) 10 Bytes
d) 12 Bytes

3) Consider the following program


.org 0x00
LDI R30, 250
LDI R20, 20
loop DEC R30
DEC R20
BRNE loop
nop
How many times the loop will be repeated?
(3 points)
a) 250
b) 50
c) 20
d) forever

Page 10 of 13
4) What are the values of R20 and R30 after the execution of the program in
part 3? (3 points)
a) 0 and 250
b) 20 and 230
c) 1 and 230
d) 0 and 230

5) Is the following instruction correct LDI R3,50?


(3 points)
a) Yes
b) No
c) Can’t be said

6) Which of the following instructions don’t affect the flags of the status
register? (2 points)
a) AND
b) OR
c) DEC
d) CALL

7) What will be the contents of R16 after the following instructions?


(2 points)
LDI R16, 0x5A
SWAP R16
LDI R17, 0x31
EOR R16, R17

a) 0x94
b) 0x6D
c) 0x31
d) 0xA5

Page 11 of 13
8) What is the difference between the two given instructions?
LDI R16,0x34 and LDI R16,$34? (3 points)

a) The first copies the hexadecimal value to R16 and the other copies the
decimal value to the R16 register
b) The first copies the decimal value to R16 and the other copies the
hexadecimal value to the R16 register
c) The first copies the hexadecimal value to R16 and the other is illegal
d) Both commands are same

9) If the stack of an AVR microcontroller contains the following values

SP
0xA0
0x10
0x00
0x02
0x30
0x00

What is the value of PC after a RET instruction? (3 points)


a) 0xA0
b) 0x0x10A0
c) 0x0x30
d) 0x3002

10) The following JMP instruction:


0x941C
0x0300
Permits to go to the following address: (2 points)
a) 0x000300
b) 0x010300
c) 0x020300
d) 0x040300

Page 12 of 13
11) The maximum number of bytes that the RJMP instruction can do starting
from the current PC is:
(3 points)
a) 1024 bytes backward and 1023 bytes forward
b) 2048 bytes backward and 2047 bytes forward
c) 4096 bytes backward and 4094 bytes forward
d) We can go to whatever location in the ROM

Page 13 of 13

You might also like