Docsity

Final Exam for Computing Mechanisms Course, Exams of Electrical and Electronics Engineering

Toggle sidebar
bg1
ECE 3035A 12:00pm Computing Mechanisms Spring 2006
5 problems, 8 pages Final Exam 2 May 2006
1
Instructions: This is a closed book, closed note exam. Calculators are not permitted. If you have
a question, raise your hand and I will come to you. Please work the exam in pencil and do not
separate the pages of the exam. For maximum credit, show your work.
Good Luck!
Your Name (please print) ________________________________________________
1 2 3 4 5
A
B
C
D total
E
20 28 24 24 40 136
pf3
pf4
pf5
pf8

Partial preview of the text

Download Final Exam for Computing Mechanisms Course and more Exams Electrical and Electronics Engineering in PDF only on Docsity!

5 problems, 8 pages Final Exam 2 May 2006

Instructions: This is a closed book, closed note exam. Calculators are not permitted. If you have

a question, raise your hand and I will come to you. Please work the exam in pencil and do not

separate the pages of the exam. For maximum credit, show your work.

Good Luck!

Your Name ( please print ) ________________________________________________

A

B

C

D total

E

5 problems, 8 pages Final Exam 2 May 2006

Problem 1 (1 part, 20 points) Iteration and Control Flow Graphs

Draw the control flow graph for the body of the following procedure.

int Load (FILE *FP, int NumRows, int NumCols, int Array[][NumCols]) {

int X, Y, Value, NumVals = 0;

for (Y = 0; Y < NumRows; Y++)

for (X = 0; X < NumCols; X++) {

fscanf(FP, "%d", &Value);

Array[Y][X] = Value;

NumVals++;}

return NumVals;}

5 problems, 8 pages Final Exam 2 May 2006

Problem 3 (2 parts, 24 points) Activation Frames

The function Foo (below left) calls function Bar after completing code block 1.

Part A (12 points) Fill in the unshaded boxes on the stack (below right) with a symbolic description and

the actual value (in decimal) for each entry in Bar’s activation frame. Do not include values for return

addresses. Label the frame pointer and stack pointer.

int Foo() {

int A[] = {3, 5};

int Y;

int Bar(int A[], int Y, int *Y);

(code block 1)

Y = Bar(A, A[1],&Y) + Y;

(code block 2)

Description Value

Foo’s FP 9900

9896 A[1] 5

9892 A[0] 3

9888 Y

Part B (12 points) Write MIPS assembly code that properly calls Bar. You should include all

instructions between code block 1 and code block 2.

label instruction comment

jal Bar

5 problems, 8 pages Final Exam 2 May 2006

Problem 4 (2 parts, 24 points) Hash Table Implementation

Part A (12 points) Write a C function that

allocates LINKBLOCKSIZE new links from the

heap, initializes them (Key and Value = -1),

and pushes them onto the head of the hash

table’s FreeLinks list. Your code should print

an error when insufficient heap space is

available.

#define LINKBLOCKSIZE 16

typedef struct Link { int Key; int Value; struct Link *Next; } Link;

typedef struct { Link **Buckets; int NumBuckets; Link *FreeLinks; int Size; } HashTable;

void Add_New_Links(HashTable *HT) {

Part B (12 points) Write a C function that performs a hash table lookup, returning the located

link if the key exists in the hash table, or NULL if it does not. You may call the hash function:

int Hash(HashTable *HT, int Key).

Link *Find_Key(HashTable *HT, int Key) {

5 problems, 8 pages Final Exam 2 May 2006

Part C (8 points) Perform at least three standard compiler optimizations on the following C code

fragment by writing the optimized version (in C) to the right.

int y = 73;

int z;

for (i=0; i < 100; i++) { Ö

x = x + (iy)+(iy);

z = y + 100;

x = x*z;}

Briefly describe which standard compiler optimizations you applied:

Part D (6 points) Explain three differences between the implementation of interrupt handling

and multitasking.

Part E (6 points) List three benefits of virtual memory in a preemptive multitasking operating

system (like Unix).

5 problems, 8 pages Final Exam 2 May 2006

MIPS Instruction Set (core)

instruction example meaning

arithmetic

add add $1,$2,$3 $1 = $2 + $

subtract sub $1,$2,$3 $1 = $2 - $

add immediate addi $1,$2,100 $1 = $2 + 100

add unsigned addu $1,$2,$3 $1 = $2 + $

subtract unsigned subu $1,$2,$3 $1 = $2 - $

add immediate unsigned addiu $1,$2,100 $1 = $2 + 100

set if less than slt $1, $2, $3 if ($2 < $3), $1 = 1 else $1 = 0

set if less than immediate slti $1, $2, 100 if ($2 < 100), $1 = 1 else $1 = 0

set if less than unsigned sltu $1, $2, $3 if ($2 < $3), $1 = 1 else $1 = 0

set if < immediate unsigned sltui $1, $2, 100 if ($2 < 100), $1 = 1 else $1 = 0

multiply mult $2,$3 Hi, Lo = $2 * $3, 64-bit signed product

multiply unsigned multu $2,$3 Hi, Lo = $2 * $3, 64-bit unsigned product

divide div $2,$3 Lo = $2 / $3, Hi = $2 mod $

divide unsigned divu $2,$3 Lo = $2 / $3, Hi = $2 mod $3, unsigned

transfer

move from Hi mfhi $1 $1 = Hi

move from Lo mflo $1 $1 = Lo

load upper immediate lui $1,100 $1 = 100 x 2 16

logic

and and $1,$2,$3 $1 = $2 & $

or or $1,$2,$3 $1 = $2 | $

and immediate andi $1,$2,100 $1 = $2 & 100

or immediate ori $1,$2,100 $1 = $2 | 100

nor nor $1,$2,$3 $1 = not($2 | $3)

xor xor $1, $2, $3 $1 = $2 ⊕ $

xor immediate xori $1, $2, 255 $1 = $2 ⊕ 255

shift

shift left logical sll $1,$2,5 $1 = $2 << 5 (logical)

shift left logical variable sllv $1,$2,$3 $1 = $2 << $3 (logical), variable shift amt

shift right logical srl $1,$2,5 $1 = $2 >> 5 (logical)

shift right logical variable srlv $1,$2,$3 $1 = $2 >> $3 (logical), variable shift amt

shift right arithmetic sra $1,$2,5 $1 = $2 >> 5 (arithmetic)

shift right arithmetic variable srav $1,$2,$3 $1 = $2 >> $3 (arithmetic), variable shift amt

memory

load word lw $1, 1000($2) $1 = memory [$2+1000]

store word sw $1, 1000($2) memory [$2+1000] = $

load byte lb $1, 1002($2) $1 = memory[$2+1002] in least sig. byte

load byte unsigned lbu $1, 1002($2) $1 = memory[$2+1002] in least sig. byte

store byte sb $1, 1002($2) memory[$2+1002] = $1 (byte modified only)

branch

branch if equal beq $1,$2,100 if ($1 = $2), PC = PC + 4 + (100*4)

branch if not equal bne $1,$2,100 if ($1 ≠ $2), PC = PC + 4 + (100*4)

jump

jump j 10000 PC = 10000*

jump register jr $31 PC = $

jump and link jal 10000 $31 = PC + 4; PC = 10000*