Professional Documents
Culture Documents
Instructions:
• Closed book/notes
• Calculators allowed
• Answer all questions
• Total pages: 15 including cover (15 Question sheets + 3 PIC Instruction set
sheets)
Page 1 of 13
Question 1: General architectures questions (16 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
b. What is the difference between RAM and ROM and why we store the
programs in the ROM? (4 points)
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)
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
96
Page 5 of 13
Question 3: AVR assembly language (40 points)
.org 0x100
main
LDI R16, 10
LDI R17, 5
Loop: call sub1
DEC R16
BRNE Loop
.org 0x160
sub1:
INC R17
RET
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)
1 point
RET (1 point)
Page 6 of 13
Solution
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)
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
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
.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.
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
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
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
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
SP
0xA0
0x10
0x00
0x02
0x30
0x00
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