Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

CENG380 Midterm Review

Exercises
Ahmad Kobeissi
(ahmad.kobeissi@liu.edu.lb) July
16, 2021

Question 1.
What is the value of R25 after the execution of the following program?

CLC
LDI R25, 0x55
ROR R25
ROR R25
a) 0x2A
b) 0x15
c) 0x95

Question 2.
What will be the contents of R16 after the following instruction?

CLC
LDI R16, 0xCC
ASR R16
LSR R16
a) 0x94
b) 0xE6
c) 0x73
d) 0x33

Question 3.
What is the size of the data bus and the address bus connecting the ATMEGA32 microprocessor to the ROM?

ROM:
Data bus is 16-bits.
Address bus is 22-bits.

Question 4.
Explain the difference between the Harvard and Von-Neumann architectures. Which one is used in the ATMEGA32
microcontrollers?

The Harvard architecture designates separate busses for ROM and RAM. While the Von-Neuman architecture employs
a shared bus.
The ATMEGA32 microcontrollers use the Harvard architecture.

Question 5.
What is the maximum supported RAM and ROM in AVR ATMEGA32?
Max. supported = 2y * x (y is number of bits on address bus, x is number of bits on data bus)
RAM has 12 address bits bus; number of addressable locations is 212 = 4KB; multiply by 1 Byte: 4KB
ROM has 22 address bits bus; number of addressable locations is 222 = 4MB; multiply by 2 Bytes: 8MB

Question 6.
An ATMEGA32 has 0x7FF as the address of its last location of its RAM.
What is the size of the RAM?

Address of last location is 2y – 1; 2047 = 2y – 1; 2048 = 2y; 2048 = 211; y = 11.


Size of RAM is 2y * x = 211 * 1 = 2KB

Question 7.
An ATMEGA32 has 0x7FF as the address of its last location of its ROM.
What is the size of the ROM?

Address of last location is 2y – 1; 2047 = 2y – 1; 2048 = 2y; 2048 = 211; y = 11.


Size of ROM is 2y * x = 211 * 2 = 2KB

Question 8.
Translate the following program into its machine code values.

Instruction In Binary In Hex


LDI R23, 7 1110 0000 0111 0111 0xE077
LDI R24, 1 1110 0000 1000 0001 0xE081
LDI R25, 10 1110 0000 1001 1010 0xE09A
ADD R24, R23 0000 1111 1000 0111 0x0F87
STS 0x603, R24 1001 0011 1000 0000 0x9380
0000 0110 0000 0011 0x0603
INC R25 1001 0101 1001 0011 0x9593

Question 9.
What are the contents of R18 and the carry flag after the execution of the following sequence of instructions?
SEC
LDI R18, 0xA9
ROR R18
ASR R18
R18: 0xEA; Carry: 0

Question 10.
What are the contents of R21 after performing the following sequence of instructions?

LDI R20, 0x24


LDI R21, 0xC8
AND R21, R20
INC R21

R21: 0x01;

Question 11.
Fill the following AVR assembly program with the appropriate code to multiply by 5 the contents of the RAM location
0x200 and store the lower byte of the result at the RAM location 0x700:
.org 0x00
LDI R16, 5
LDS R10, 0x200
MUL R16, R10
STS 0x700, R0

Question 12.
Fill the following AVR assembly program with the appropriate code to subtract the contents of the RAM location
0x600 from the contents of the RAM location 0x700 and store the result in R5:

.org 0x00
LDS R16, 0x700
LDS R17, 0x600
SUB R16, R17
MOV R5 , R16

Question 13.
What is the value of the C flag after the execution of the following program?

LDI R22, 0xCC


ASR R22
LSR R22

a) 0
b) 1
c) Unknown

Question 14.
Choose the answer from the multiple choices that correctly reflects the values of the SREG flags after the execution of
the following program:

LDI R20, 0x12


LDI R21, 0xA5
SUB R20, R21

a) Z=0, N=0, H=0, C=0, V=0, S=0


b) Z=0, N=0, H=1, C=1, V=0, S=0
c) Z=1, N=0, H=0, C=0, V=0, S=0
d) Z=1, N=1, H=1, C=0, V=0, S=1

Question 15.
The following instruction is a correct instruction:

LDI R15, 0x12

a) True
b) False

Question 16.
How many general–purpose registers do the AVR microcontroller have?

a) 8
b) 16
c) 32
d) None of the mentioned

Question 17.
What is the mnemonic for the last AVR general-purpose register?

a) R0
b) R16
c) R31
d) R32

Question 18.
What will be the contents of R16 after executing the following program?

LDI R16, 0xCD


LDI R17, 0x13
OR R16, R17
DEC R17

a) 0xDE
b) 0xDF
c) 0xE0

Question 19.
What will be the contents of R16 after executing the following program?

LDI R16, 0xCD


LDI R17, 0x13
EOR R16, R17
DEC R16
SWAP R16

a) 0xDE
b) 0xDD
c) 0x13

Question 20.
To divide a signed number in register R16 by 2, we can use the instruction:

a) LSL R16
b) LSR R16
c) ASR R16
d) ROR R16

Question 21.
Which instruction clears the carry bit?

a) SEC
b) CLC
c) BCLR

You might also like