Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

Computer Architecture Midterm Exam

CS 198:211

Summer Session 2022

Section 1: Programming Questions

In this section you will write C code that will fulfill each assigned task. For this       portion you should write as correct code as you are able. There will be no penalty for miscellaneous errors (i.e., capital vs lowercase, missing semi-colons, miss-       spelling, etc.). There will be penalties for code that “shows the general idea” but  is incorrect (i.e., creating a 1D array when the intent was to create a 2D array)

1. 2D Manipulation (10 points)

Write a complete program (this includes import statements, main, and return)       that will create a 4x4 2D array. Let the top left index be numbered 0 incrementing down the columns to the bottom right index, numbered 15 as shown in the figure below. Fill each index of the array with the value of the index % 3. Namely, the      top left index should be 0 % 3, the top right index should be 12 % 3, the bottom     left index should be 3 % 3, and the bottom right index should be 15 % 3, etc. Print out the values of the 2D array in the numeric order of the indices (0, 1, … 15), four values per each line, to standard output. Lastly, print out the sum of all the values of the 2D array.

0   4    8   12

1   5    9   13

2   6  10  14

3   7  11  15

2. Hash Table (6, 4 points)

a) Assume your following code will be in main (you do not have to write main or  any other non-specified code yourself). Write code for a hash table that contains integers. Your hash table should be appropriately malloc-ed. Your hash table        should have a total of 1000 buckets. In the case of a collision, you should remove whatever item was previously in the bucket, print the value on its own line to      standard output, and then replace the item with the new value. Use a loop to      populate your hash table with the numbers 1-5000.

b) Create an int function called search” . This function should take your hash  table as a parameter and an int x. Your function should return the value at the given index x of the hash table. Any error conditions should return -1.

3. Linked List (2.5, 2.5, 5 points)

a) Define a struct called data that has 3 fields. It should hold one int, a string of at most 20 characters, and a pointer to another data struct.

b) Create a void function called “link_together” . This function should take in two data struct pointers, a and b. The function will set the value of a’s data struct      pointer field to b.

c) Assume your following code will be in main (you do not have to write main or any other non-specified code yourself). 1) Write code that will initialize two data structs. 2) Set the int fields to any value you want. 3) Call your link_together”   function and pass it both of your structs in the order you initialized them.

4) Change the value of the int field of your second struct by calling your first struct. 5) Lastly, free your structs.

Section 2: Multiple Choice

In this section, there are multiple choice questions. You can circle, underline, or write the letter corresponding to your answer. Questions are worth 1 point.

1. The most popular computing model used today is the:

A) Rutgers Model

B) Harvard Model

C) Memory Model

D) Von Neumann Model

2. A major difference between SRAM and DRAM is that SRAM:

A) Is slower and is cheaper

B) Is faster and is cheaper

C) Is slower and is more expensive

D) Is faster and is more expensive

3. The L1 Cache is located in the:

A) Registers

B) CPU

C) Highest level of memory

D) Lowest level of memory

4. If a cache is direct mapped, this is the equivalent of saying:

A) Associativity = 1

B) Sets = 1

C) Cache Size = 1

D) Block Size = 1

5. There are _______ bits in a byte.

A) 2

B) 4

C) 8

D) 16

6. Structure Padding refers to:

A) The process of translating the code of a structure to bits

B) Allowing extra space between all fields of a struct as buffers

C) Changing the size of a struct based on what fields are present

D) Setting the best size of a struct based on the processor’s word size

7. The CPU clock sends signals to hardware that indicate intervals to take an action, process, or wait. These intervals are called:

A) Cycles

B) Breaks

C) Clock Rate

D) Clock Speed

8. Different hardware components communicate with each other along the:

A) Bridge

B) Bit cables

C) BUS

D) I/O

9. ______ are the fundamental building blocks of physical computer memory.

A) Storage Cells

B) Memory Cells

C) Bits

D) Data Bytes

10. ______ are the fundamental building blocks of digital computer memory.

A) Storage Cells

B) Memory Cells

C) Bits

D) Data Bytes

11. To complete a Disk Direct memory access transfer the disk will:

A) Record data in Main Memory and notify the CPU

B) Record data in the CPU

C) Record data in the Disk Controller and give the address to Main Memory

D) Record data in Main Memory and notify the BUS

For questions 12-16 consider the following code:

void foo(int a, int* b){

a++;

*b = 2;

b = &a;

*b = 3;

//15, 16

}

int main(){

int a = 0;

int* b = &a;

printf(“%x %x\n”, &a, &b); //12

foo(a, b);

printf(“%x %d\n”, &a, a); //13

//14

//15, 16

}

12. In this print statement: printf(“%x %x\n”, &a, &b); //12 what will the code print?

A) 0 0

B) the address of a twice

C) the address of a and then the address of b

D) the address of a and then the value of b

13. In this print statement: printf(“%x %d\n”, &a, a); //13 what will the code print?

A) the address of a and then 3

B) the address of a and then 2

C) the address of a and then 0

D) 0x0 and then 0

14. At the point denoted //14, consider if the following code was injected into this position:

int* c = &a;

if(b == c)

printf(“1”);

if(*b == *c)

printf(“2”);

if(&b == &c)

printf(“3”);

what will the additional code print?

A) 123

B) 12

C) 2

D) 23

E) 13

F) 3

15. Consider both places denoted //15, 16 The value of *b in both locations is:

A) different

B) the same

C) Due to locality, there is no relationship between the variables

D) The relationship is undefined behavior

16. Consider both places denoted //15, 16 The value of &b in both locations is:

A) different

B) the same

C) Due to locality, there is no relationship between the variables

D) The relationship is undefined behavior

Section 3: Short Answer

In this section you will be given a series of short answer questions. Answer each prompt with a numeric answer and the work it took to derive your answer or a  couple (2-4) sentences as applicable.

1. (3 points)

A programmer sees some code and decides to optimize it. The resulting code is shown below.

int foo(int i, int x){

for(i = i; i; i--)

x <<= 1;

return(x);

}

What is the purpose of this function and/or what mathematical operation does it mimic? Why might this code be considered more efficient than the original code that it was based on? Lastly, what is a major issues/error condition that exist in    this code?

2. (7 points)

Number Representation

Use 6 bits for the representations for this question.

a) Show the 2’s complement representation of the number 4 and -4

b) Show the 1’s complement representation of the number 4 and -4

c) Show the unsigned magnitude representation of the number 4 and -4

d) Use 2’s complement to add 15 and 17

e) Use 2’s complement to subtract 5 from 3 (what is 3 – 5)

3. (10 points)

Consider 9-bit IEEE for this question. There will be 1 bit for the sign, 3 bits for the exponent, and 5 bits for the mantissa.

a) Convert 0b011100100 to decimal

b) Convert 0b110011000 to decimal

c) Convert 9.125 to IEEE

d) Convert 0.25 to IEEE

e) How many representations for the value 0 are there?

f) Give the IEEE representation(s) for the number 0.

4. (2 points)

Why can a computer scientist claim that x2 can be < 0?

6. (2 points)

Round the following binary numbers using the Round-to-Even method:

a) Round 0b100.10 to 3 digits.


b) Round 0b11.001101 to 4 digits after the decimal

7. (7 points)

Consider a partially filled cache (visualized below) with a capacity of 64 bytes. The Memory addresses have been partitioned into Tag | Index | Offset and converted into decimal. It is using the FIFO replacement policy. You can assume that it is       being filled left to right.

1 | 0 | 1

 

 

 

3 | 1 | 2

8 | 1 | 3

5 | 1 | 2

 

5| 2 | 3

6 | 2 | 3

7 | 2 | 3

 

10 | 3 | 4

31 | 3 | 1

42| 3 | 0

 

a) What is the associativity of the cache?

b) For each of the following converted Memory Addresses indicate if it is a Hit” or “Miss” . In the case of a miss, the address should be entered into the cache.     Specify which set the address was entered into. In the case of an eviction specify which  Memory Address was evicted (answer None” if no addresses were           evicted). Each of the following is entered sequentially and thus may affect the     result of subsequent entries.

.

1 | 0 | 1

H  or  M

Set #

Evicted Address:

II.

5 | 1 | 1

H  or  M

Set #

Evicted Address:

III.

6 | 1 | 1

H  or  M

Set #

Evicted Address:

IV.

7 | 1 | 1

H  or  M

Set #

Evicted Address:

.

33 | 3 | 1

H  or  M

Set #

Evicted Address:

VI.

5 | 1 | 1

H  or  M

Set #

Evicted Address:

Section 4: Long Answer

In this section you will be given a prompt. Answer each prompt fully with a meaningful, supported, and well thought out answer (6-10 sentences).

1) (6 points)

Number Representation is important as a method of encoding small and large     numbers alike into a meaningful representation that the computer can interpret. Give some analysis of number systems. What is the importance of number            systems? What can make a number representation good or bad . How might one representation be better” or worse” than others representations? How can      knowledge of number representation improve programming skill?

(Topics include but are not limited to: binary, octal, hex, IEEE, rounding, …)

2) (7 points)

What is the core concept of a cache? What are 3 steps, properties, or algorithms that a cache has/uses to be efficient?

Regarding cache algorithms, how might choosing a different cache algorithm both increase or decrease efficiency? Give an example (real or hypothetical).

3) (7 points)

Pointer are unique to C. Describe the functionality of pointers and what makes      this data type unique. In C, arrays are almost the same as pointers if implemented correctly. What property of pointers allows them to act as we would expect an      array? What is a similarity in practice or implementation of arrays and pointers?    What is a difference in practice or implementation of arrays and pointers? Give an example of initializing an 3x4 2D int array. Give an example of malloc-ing a 3x4 2D array using pointers.