Sample Exam Questions
Sample Exam Questions
Sample Exam Questions
1. Convert the following numbers from the original base to the specified base:
a) 12310 Æ ______________2
b) 101012 Æ ______________10
c) 108410 Æ ______________16
d) A516 Æ ______________10
e) 110010012 Æ ______________16
f) 2D516 Æ ______________2
7. Represent the following numbers in IEEE 754 32-bit floating point notation:
a) 1.5
b) 1084
c) –1
d) –13.75
Refer to the AVR Instruction Set document on the course website (in the AVR
Material section).
11. What do the following letters in a typical status register stand for and how are they
generated?
a) Z
b) C
c) V
d) N
e) S
12. What is the main difference between the memory models of Princeton (von Neumann)
and Harvard architectures?
13.
Memory address Data
0x00000100 0xAF
0x00000101 0x1B
0x00000102 0xC2
0x00000103 0x05
Based on the above, what is the 32-bit word stored at the memory address 0x00000100
in a:
a) big-endian machine?
b) little-endian machine?
14. Can you design an 8-bit instruction format that can allow 4 2-operand instructions for a
machine with 8 registers?
15. What do these notations mean in AVR assembly programming? Where are they used?
16. Where are the functions low() and high() utilised? Load -200 into a two byte number.
17. What are the differences between Macros and Functions? In what circumstances are each
of them appropriate, and when should each be avoided? Write a Macro called Invert to
invert the value of a register (Note: The register should be sent as a parameter)
18. What are word addressable and byte addressable? Explain them with examples using
AVR memories.
19. Consider the following AVR assembly code segment and fill the initialization part?
.dseg
array: .byte 20
.cseg
data: .dw 0x1234
// Initialize the X pointer with array
_______________________
// Initialize the Z pointer with data
_______________________
20. What are little endian and big endian representations ? Which endian is used in AVR?
b) cp r16,‘L’
d) ldi r40, 23
23. How do you multiply a two byte number by a one byte number? (Explain using a
simple example). Do we have to consider the carry bit in the STATUS register for this
case?
24. Investigate the different ways of writing AVR assembly code for the following
scenarios,
a) Copying a pair of registers into another pair of register.
b) Multiply a number by 4.
c) Divide a number by 4.
25. When are MUL, MULS and MULSU instructions used and how are they are used?
Write AVR assembly code to perform multiplication for the following set of numbers,
a) 10, 12 (1 byte result) d) 32,258 (2 bytes result)
b) -11,11 (1 byte result) e) -352, 28 (2 bytes result)
c) -4,-14 (1 byte result) f) -27,-375 (2 byte result)
26. 1 Minimally modify the code below to add two numbers (in r17:r16 and r19:r18) when
the result is bigger than 255.
ldi r16, 1
ldi r17, 0
ldi r18, 255
ldi r19, 0
add r16, r18
add r17, r19
26.2 Write AVR code to add two 32 bits values?(Using R16-R23 to hold all values.)
a = 0x00000100
b = 0x002000FF
27. Please complete the following table with instructions used for each operation.
Write to
Read from
28. How do you setup a port to act as an input port or as an output port in AVR? What
instructions are used to read from an I/O port? What instructions are used to write to
an I/O port?
Address
0x1000 .def grade=r20
0x1002 .include "m64def.inc"
where each pair of bits ISCn1 and ISCn0 mean the following for INTn:
The EIMSK register is used to enable the external interrupts and looks like this:
In “m64def.inc”, the values in these registers have been defined to their bit value. e.g., ISC00 =
0, ISC11=3 and INT2=2. Knowing this, examine the following code:
.def temp=r16
ldi temp, (0b10 << ISC00) | (0 << ISC10) |(0b11 << ISC20)
sts EICRA, temp
ldi temp, (1 << INT0) | (1 << INT2)
out EIMSK, temp
sei
a) What is the value (in binary) that is written to the EICRA register?
b) Why do we use this approach to set up the register values?
c) Which external interrupts can occur, and when will they occur?
d) What is the difference between the ‘sts’ instruction and the ‘out’ instruction?
31. This question looks at the registers associated with PORT A. The following tables might help:
a) What is the purpose of the DDRA register?
b) What is the purpose of PORTA0 when DDA0 = 1?
c) What is the purpose of PORTA0 when DDA0 = 0 and PUD = 0?
d) What is the purpose of the PINA register?
32. The Keypad on the AVR boards is a set of 16 push buttons. The keypad has four rows and four
columns, accessible via the pins R0-R3 and C0-C3. When you push a button on the keypad, it
connects the column of the key to the row of the key as follows:
C0 C1 C2 C3
1 2 3 A R0
4 5 6 B R1
7 8 9 C R2
* 0 # D R3
One method to correctly read what keys are being pressed is to:
1: Set up the rows so that they read a Logic 1 when none of the buttons on the row is
pushed.
2: Set one column to Logic 0 and all other columns to Logic 1.
3: Read the values of the row pins. If a row reads as Logic 0, you know that the switch at
that row and column must be pushed.
4: Set a different column to Logic 0 and read the rows.
5: Repeat steps 3 and 4 until a switch is found to be pressed or you run out of columns.
6: Repeat steps 2-5 again if you want to see whether a different switch is pushed.
Part of your third lab requires you to perform this algorithm. Steps 2-5 should be fairly simple
to code, but step 1 is not so obvious. The way to accomplish this is with pull-up resistors. A
pull-up resistor ties an input pin to Logic 1 via a resistor. This means that an input pin will still
read any value that is input, and will read Logic 1 if disconnected.
To further understand this, look at switch 5 in the above diagram. When none of the switches
connected to row 1 are pushed, the circuit (with pull-up shown) looks like this:
R1
If read, the port would read a Logic 1 via the pull-up resistor.
R1
In this case, the port connected to R1 will always read the current value of C1. When C1 is
Logic 0 there will be a voltage drop across the resistor, but this will not affect the value being
read. Thus, the pull-up resistor accomplishes the desired task.
a) How do you setup an AVR I/O port so that it has pull-up resistors connected to its input
pins? (See question 2 of this tute)
b) Write the code to find a switch that has been pushed by scanning either the columns or rows.
(You have to do this for your lab, anyway)
c) Can you see an electrical problem with this scanning method when two switches on the
same row are pushed at the same time (e.g., 5 and 6)? How could you correct this? (Hint:
There might be something better you can do than output logic 1s to the columns you are not
testing.)