MT Fall2021 PDF

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

Bilkent University

2021-2022 Fall Semester

EEE 212

Midterm Exam
05.11.2021 Friday, 10:30 – 12:20
Duration: 110 minutes

Name
Surname
Course Code EEE 212

Q1 Q2 Q3 Q4 TOTAL

15 25 30 30 100
Q1 [15 points]: Assume that the following 8-bit format is used to represent floating-point
numbers in 8051.

S Exponent Mantissa

0/1
Sign 3-bit 4-bit fraction
bit exponent fraction
point

FP value = (-1)S x (1.Mantissa) x 2(Exponent - 3)


__________________________________________________________________________________________________

S Exponent Mantissa

0 0 0 1 1 1 0 0

FP value = (-1)0 x (1.1100)b x 2(1 - 3) = (1 + 1/2 +1/4) x 2(1 - 3) = 1.75 x 2(1 - 3) = 0.4375

S Exponent Mantissa

1 1 1 1 1 0 0 0

FP value = (-1)-1 x (1.1000)b x 2(7 - 3) = - (1 + 1/2) x 24 =- 1.5 x 24 = -24

A) What is the largest floating-point number you can represent in this format?
What is the smallest value?
B) Write an assembly code that will compare the two floating-point (fp) values in
the above format provided from P1 and P2 (most significant bit P1.7/P2.7
holds the sign bit, followed by exponent and mantissa as shown in the below
figure). Set the pin 0 of P0 (P0.0) to 1 if the fp number in P1 is greater than or
equal to the fp value in P2; otherwise, send 0 to the same pin (P0.0).

S Exponent Mantissa

D7 D6 D5 D4 D3 D2 D1 D0
Q2 [25 points]: There are two null-terminated strings stored at internal ROM address
0200h and 0300h. Write an algorithm that will set the value of bit at address 00h (least-
significant bit of register 20h) if one of the strings is a substring of the other. Otherwise it
will clear the content of this bit (00h). (Assume that the arrays do not overlap) Hint: You
can update DPH and DPL separately.

Q3 [30 points]: Generate a continuous sine-wave with frequency 2KHz and amplitude
15d (decimal) for a 8051 based microcontroller (AT89C51), and output it from P1. For the
implementation you are asked to quantize the continuous curve such that the wave is
similar to the figure below (assuming an external crystal frequency of 12 MHz ). Use a
lookup table for the quantized values.

15

T=1/f

15
10
5

-5
T/2
-10
-15
T/10
Q4 [30 points]: In this question you will be implementing a digital phonebook using a
simple hash function. Hashing is a technique that maps a given data to a fixed number as
shown below using a simple function like modulo operation and examples.

NAME (6 bytes - ASCII) Office Phone No Phonebook


(1 byte - hexadecimal)
30h
J' 'O' 'H' 'N' _ 15h
.
J' 'A' 'M' 'E' ’S' 25h .
.
D' 'A' 'V' 'E' _ 39h .
K' 'A' 'T' 'E' _ 12h .
S' 'A' 'R' 'A' 'H' 50h .
. .
J' 'O' ‘E' _ _ 17h
6Fh
…. … T=64d=40h
T = #number of entries in the phonebook
_ : corresponding byte is 00h (Assume this is always a power of 2 and
less than 128)
30h = staring address in the RAM
30h + T -1 = 6Fh = RAM address of the last
entry
JOE : KATE :

4Ah + 4Fh +45h = DEh (=170d) 4Bh + 41h + 54h + 45h= 125h
DEh (mod T=40h=64d) = 2Ah (=42d) (Since T=2n & T< 128, we can ignore carry)
25h (mod T=40h=64d) = 25h (=37d)
RAM content @ (30+2A)h = 5Ah is 17h.
RAM content @ (30+25)h = 55h is 12h.

Assume that hash-table size (T) is chosen such that there is no collision
(i.e., hash (name i ) ≠ hash(name j ) for any i and j )

A) Write a subroutine called READ, which reads 7 bytes from P1 with a certain sampling
period and accumulates the sum of the first 6 bytes in R7, and stores the last one in
R6. After each byte read, you need to call a subroutine named SAMPLINGDELAY to
achieve this sampling period. (You can assume that this delay subroutine is already
implemented and provided to you. You just need to call it after reading each byte).

B) Write a second subroutine called HASH which takes the modulo T of the value in R4,
sums it with the starting address of the phonebook in the RAM (assume it is 30h), and
stores the result in R5. T is a constant, but you are not given its numeric value (do not
use the value in the above example).

C) Write an assembly code (main program to be sent to your 8051 based microcontroller)
which continuously
1. Reads from P1 using the READ subroutine from PARTA (assume a correct
implementation is provided, and you are just asked to call it in this part.)
2. Using the subroutine from PARTB, takes the modulo of the sum (the first 6 bytes)
and adds it to the starting address of the phonebook as described in PARTB
(assume a correct HASH implementation is provided for this part.)
3. Writes the value in R6 (7th byte that READ subroutine saved) to the RAM address
stored in R5 by HASH subroutine.

You might also like