CS61C Midterm 1, Fall 2000: Computer Architecture and Assembly Programming Questions, Exams of Structural Analysis

The cs61c midterm 1 exam from the university of california, berkeley, fall 2000. The exam covers various topics in computer architecture and assembly programming, including components of a computer, machine language assembly code, floating point numbers, networks, and hash tables. Students are required to answer multiple-choice and programming questions.

Typology: Exams

2012/2013

Uploaded on 04/02/2013

shalabh_li43y
shalabh_li43y 🇮🇳

4.5

(18)

88 documents

1 / 7

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS61C, Fall 2000
Midterm 1
Professor D. Patterson
Question #0: Sign-in Question (-1 point if not followed): Fill out the front page correctly and write your
login at the top of each of the pages. Circle your login initials so we can read them.
Question #1: I am a computer (Parts of a Computer) (3 points)
(a) Name the five
components of a
computer:
(b) Consider your body, and how it is like a computer system. For each component
you listed to the left, give one example of a body part that corresponds to that
component. You may not use the same body part more than twice.
1. 1.
2. 2.
3. 3.
4. 4.
5. 1.
Question #2: Minding your p's and q's (Pointers) (5 points)
Below is a segment of C code:
char *p, *q, x = 'a', y = 'b';
p = x
q = y
*q = *p++;
q = p;
To answer the following questions, you may use any $t register. Assume the address of x is 1000, address
of y is 1004, p is associated with register $s0, q with $s1. Please keep your code brief.
i. [1 point] What is the MAL code for p = &x;
ii. [1 point] What is the MAL code for q = &y;
iii. [1 point] What is the MAL code for *q = *p++;
iv. [1 point] What is the MAL code for q = p;
v. [1 point] What is the value of q at then end of this section of code?
Question #3: My numbers are changing! (Pilable Data) (5 points)
A = 0x20C89000
(a) [1 point] Give the binary equivalent of A:
_______________________________________________________________________
CS61C, Midterm 1, Fall 2000
CS61C, Fall 2000Midterm 1Professor D. Patterson 1
pf3
pf4
pf5

Partial preview of the text

Download CS61C Midterm 1, Fall 2000: Computer Architecture and Assembly Programming Questions and more Exams Structural Analysis in PDF only on Docsity!

CS61C, Fall 2000

Midterm 1

Professor D. Patterson

Question #0: Sign-in Question (-1 point if not followed): Fill out the front page correctly and write your login at the top of each of the pages. Circle your login initials so we can read them.

Question #1: I am a computer (Parts of a Computer) (3 points)

(a) Name the five components of a computer:

(b) Consider your body, and how it is like a computer system. For each component you listed to the left, give one example of a body part that corresponds to that component. You may not use the same body part more than twice.

**1. 1.

  1. 1.**

Question #2: Minding your p's and q's (Pointers) (5 points) Below is a segment of C code:

char *p, *q, x = 'a', y = 'b';

p = x q = y *q = *p++; q = p;

To answer the following questions, you may use any $t register. Assume the address of x is 1000, address of y is 1004, p is associated with register $s0, q with $s1. Please keep your code brief.

i. [1 point] What is the MAL code for p = &x;

ii. [1 point] What is the MAL code for q = &y;

iii. [1 point] What is the MAL code for *q = *p++;

iv. [1 point] What is the MAL code for q = p;

v. [1 point] What is the value of q at then end of this section of code?

Question #3: My numbers are changing! (Pilable Data) (5 points)

A = 0x20C

(a) [1 point] Give the binary equivalent of A:

_______________________________________________________________________

For the following 3 questions (b, c, d) you may leave parts of your answers as signed sums of powers of two [e.g. -(2^2+...2^19)]. Do not leave any part of your answers in hex. No hex!

(b) [1 point] Give the decimal equivalent of A if A is interpreted as an integer in 2's-complement notation:

(c) [1 point] Give the decimal equivalent of A if A is interpreted as a single-precision IEEE 754 floating point number:

(d) [2 points] Give the MAL instruction equivalent of A if A is interpreted as an instruction in machine language format:

Remember, no hex!

Question #4: Can a C integer float? (Floating Point) (2 points)

(a) Can all int in C (for the MIPS Instruction Set) be converted to a single precision floating point number and back to integer without changing the value of the integer? Why or why not?

(b) Can an int in C (for the MIPS Instruction Set) be converted to a double precision floating point number and back to integer without changing the value of the integer? Why or why not?

Question #5: Is the Internet really this fast? (Networks) (10 points)

You are writing a program to send an array X from machine A to machine B over a network. Let us assume that ints are 32 bits and chars are 8 bits, and the operating system on computer A implements a function

void send(char *machineName, char *sendbuf, int nbytes);

that sends to the machine indicated by the first argument (machineName) nbytes of data starting at the byte pointed to by sendbuf.

You are considering two ways to implement the program:

/* First way */ int main(int argc, char *argv[]) { int X[500,000]; int I, *Y = X; for (I=0; I send("B", (void *)Y, 4000); exit(0); }

/* Second way */ int X[500000]; send("B", (void *)X, 2000000); exit(0);

C) hastable.o and philspel.o are produced independently, each with a symbol table and relocation information. As a result, future editing of philspel.c will not require recompilation of hashtable.c.

D) References from philspel.o to the function findData are patched. The jump target corresponding to readDictionary is changed as well.

E) M'Piero writes proj1 in C. M'Piero uses C, instead of assembly, because M'Piero knows that optimizing compilers can produce assembly language programs almost as well as human experts, and because memory is cheaper these days.

The order of events is (write your letters in the boxes) :

_ _ _ _ _

Question #7: If only I could write in C? (MIPS) (9 points)

Executing this program in spim, will it reach the next label? If not, why not, and if so, what will the value of $t1 be (in hex) and why? Assume all registers are initially zero. This is a correct translation from MAL to TAL; both versions are there only to assist you with the problem.

(a) [3 points]

Address TAL MAL [0x00400000] lui $1, 64 __start: la $s0, loop [0x00400004] ori $16, $1, 12 [0x00400008] lui $8, 1 addiu $t0, $0, 0x [0x0040000c] bne $0, $11, 12 loop: bne $0, $t3, next [0x00400010] lw $10, 0($16) lw $t2, 0($s0) [0x00400014] addu $9, $9, $8 addu $t1, $t1, $t [0x00400018] jr $16 jr $s [0x0040001c] ori $2, $0, 10 next: done [0x00400020] syscall

$t1 = 0x__________

Why/Why not? ________________________________________________________

We've added a couple of instructions. Now, if the program reaches the next label, what will the value of $t1 be (in hex) and why? If not, why not?

(b)[6 points]

Address TAL MAL [0x00400000] lui $1, 64 __start: la $s0, loop [0x00400004] ori $16, $1, 12 [0x00400008] lui $8, 1 addiu $t0, $0, 0x [0x0040000c] bne $0, $11, 20 loop: bne $0, $t3, next [0x00400010] lw $10, 0($16) lw $t2, 0($s0)

[0x00400014] addu $10, $10, $8 addu $t2, $t2, $t [0x00400018] sw $10, 0($16) sw $t2, 0($s0) [0x0040001c] addu $9, $9, $8 addu $t1, $t1, $t [0x00400020] jr $16 jr $s [0x00400024] ori $2, $0, 10 next: done [0x00400028] syscall

$t1 = 0x__________

Why/Why not? ________________________________________________________

Question #8: Can you help me find my integer? (Pointers in C and MIPS) (14 points)

In your first project, philspel, we provided you with a typical hash table implementaion. A similar, albeit simplified, hashtable is defined below. Note that the keys and values stored in this hashtable are simply integers:

/* hashBuckets store the individual entries of the hash table.

  • Since it is possible for two different keys to hash to the
  • same value, the buckets can be chained via the next pointer
  • they contain. The next pointer of the final bucket in a
  • chain has value NULL, and, in this implementation, you may
  • assume that NULL has value 0 */ typedef struct HashBucket { int key; int value; struct HashBucket *next; } HashBucket;

/* The hashtable itself is an array of pointers to HashBuckets.

  • TABLE_SIZE is an arbitrary constant. hashTable is passed in
  • to findData */ HashBucket *hashTable[TABLE_SIZE];

/* The findData method looks up the given key in the given hash

  • table, and returns the value associated with that key */ int findData(int key, HashBucket **hashTable) { unsigned int location = hashFunction(key) % TABLE_SIZE; HashBucket *lookAtMe = hashTable[location]; while (lookAtMe != NULL) { if (lookAtMe->key == key) { return lookAtMe->value; } lookAtMe = lookAtMe->next; } return ERROR_NOT_FOUND; }

j fin

next_bucket:

________________________ #_______________________

j loop

not_found:

addiu $v0, $v0, ERROR_NOT_FOUND # Pretend ERROR_NOT_FOUND is a

constant

fin: addiu $sp, $sp, 28 jr $ra

Posted by HKN (Electrical Engineering and Computer Science Honor Society)

University of California at Berkeley

If you have any questions about these online exams

please contact [email protected].

Posted by HKN (Electrical Engineering and Computer Science Honor Society)University of California at BerkeleyIf yo 7