hw1 solution

4
HW1 solutions (If you find any mistakes, please email me-- [email protected]) 8.1 (a) 8. For the first FOR loop, data[0] is not in the cache, one miss , so processor fetches it in the main memory and copy the block it is stored to the cache. Thus, data[0] and data[1] both are copied to cache set 1. Next step, processor fetches data[1] and it is in the cache, no miss. So the first FOR loop, total 8 miss. For the second FOR loop, all the data has been stored in cache, so no miss. Data[14],Data[15] Data[12],Data[13] Data[10],Data[11] Data[8],Data[9] Data[6],Data[7] Data[4],Data[5] Data[2],Data[3] Data[0],Data[1] Set 0 Set 1 ….. Set 8 …..

Upload: minjie-zhu

Post on 18-Jul-2016

11 views

Category:

Documents


0 download

DESCRIPTION

Homework solution to Introduction to Embedded system LeeshiaProblem 8.1 8.3 9.1

TRANSCRIPT

Page 1: HW1 Solution

HW1 solutions

(If you find any mistakes, please email me-- [email protected])

8.1

(a) 8.

For the first FOR loop, data[0] is not in the cache, one miss , so processor fetches it in the main memory and copy the block it is stored to the cache. Thus, data[0] and data[1] both are copied to cache set 1. Next step, processor fetches data[1] and it is in the cache, no miss. So the first FOR loop, total 8 miss. For the second FOR loop, all the data has been stored in cache, so no miss.

Data[14],Data[15] Data[12],Data[13] Data[10],Data[11] Data[8],Data[9] Data[6],Data[7] Data[4],Data[5] Data[2],Data[3] Data[0],Data[1] Set 0

Set 1

…..

Set 8

…..

Page 2: HW1 Solution

(b) 32. N=32 . Total 32*4=124 Byte For the first FOR loop, the first 16 data is the same as the (a), 8 miss. Next, the processor will fetch the block where data[16] and data[17] are stored in the main memory and replace data[0] and data[1] in set 0. And then data[18] and data[19] replace data[2] and data[3]……. So 16 miss. For the second FOR loop, the processor will fetch data[0] first, but it has been replaced by data[16], so fetch it again and copy the block to cache. For every block, one miss, one hit. So also 16 miss. So total 16+16=32 miss.

Data[30],Data[31] Data[28],Data[29] Data[26],Data[27] Data[24],Data[25] Data[22],Data[23] Data[20],Data[21] Data[18],Data[19] Data[16],Data[17] Data[14],Data[15] Data[12],Data[13] Data[10],Data[11] Data[8],Data[9] Data[6],Data[7] Data[4],Data[5] Data[2],Data[3] Data[0],Data[1]

Set 0

Set 1

…..

Set 8

Page 3: HW1 Solution

(c) 16.

For the first FOR loop, the processor fetches every data from main memory, and every set has two lines (2 blocks). Every data is stored in a single block. Total 16 miss for the first FOR loop. For the second For loop, all the data have been stored in cache, so no miss.

Data[16] Data[15] Data[14] Data[13] Data[12] Data[11] Data[10] Data[9] Data[8] Data[7] Data[6] Data[5] Data[4] Data[3] Data[2] Data[1] Data[0]

Line2 Line1 Line2 Line1 Line2 Line1 Line2 Line1

Set 0

Set 1

Set 2

Set 8

…..

Page 4: HW1 Solution

8.3

(a) n is in C. (Global variable) m is local variable, in C. a is a global variable , so in D.

(b) Because the input for function foo is 0, so it will stop and print n=0. (c)Because the input for function foo is 1, it will keep calling itself and increasing the value of n, until n is large enough to cause memory overflow.

9.1

Every byte sending time is t=8/19200=0.416667ms. F= 50MHz. So N=t*F=20834 cycles. (Start bit and end bit can be either included or not) 1st byte: For statement 2 cycles (Increment is done when this loop in finshed) While statement 2 cycles Assignment 1 cycle Sending time 20834 cycles. (Processor has to keep executing while

statement until it is done) I increment 0 cycle (Overlapped with the sending time) Total 20839 cycles 2nd -7th byte: For statement 0 cycles (Overlapped with the last byte sending time ) While statement 2 cycles Assignment 1 cycle Sending time 20834 cycles. I increment 0 cycle (Overlapped with the sending time) Total 6* 20837=125022 cycles 8th byte: For statement 0 cycles (Overlapped with the last byte sending time ) While statement 2 cycles Assignment 1 cycle Sending time 0 cycles. (Processor doesn’t have to wait and executes

the next statements ) I increment 1 cycle For statement 2 cycle (I=8 and compare with 8) Total 6 cycles In total, 20839+125022+6=145867 cycles