Docsity

Computing Mechanisms Exam - Spring 2006, Exams of Electrical and Electronics Engineering

Toggle sidebar
bg1
ECE 3035 A & B Computing Mechanisms Spring 2006
4 problems, 7 pages Exam Two 12 April 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
A
B
C
D total
E
28 24 22 26 100
pf3
pf4
pf5

Partial preview of the text

Download Computing Mechanisms Exam - Spring 2006 and more Exams Electrical and Electronics Engineering in PDF only on Docsity!

4 problems, 7 pages Exam Two 12 April 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

4 problems, 7 pages Exam Two 12 April 2006

Problem 1 (5 parts, 28 points) WordSearch Baseline

Part A (4 points) Suppose the letter map is composed of a rectangular grid of cells where each

cell contains a letter A – Z, and letters are equally likely to occur. If the map contains N cells,

how many cells, on average, must be examined to match the first letter of the match word?

(Don’t include cells that are examined to match the remaining three characters.)

Part B (4 points) On average, what is the probability that the first character of a match word

does not match a cell being examined? You may express your answer as a fraction.

L1: addi $01, $01, -1 # I- swi 525 # I- bne $02, $11, L1 # I- add $08, $01, $00 # I- div $01, $03 # I- mfhi $06 # I- mflo $07 # I- slt $04, $06, $16 # I- … (many more instructions)

Part C (6 points) The code fragment above is the start of the main search loop. Suppose the

letter map has N letters. Write an expression for the total number of instructions executed for all

examined cells that do not match the first character of the match string. Show all work.

Part D (6 points) Recall that each dimension of the word map is [4..15] inclusive. What is the

average number of cells ( N ) in a map? For maximum credit, show all work.

L2: add $01, $01, $05 # I- swi 525 # I- bne $02, $12, L3 # I- add $01, $01, $05 # I- swi 525 # I- bne $02, $13, L3 # I- add $01, $01, $05 # I- swi 525 # I- bne $02, $14, L3 # I- jr $18 # I- L3: add $01, $08, $00 # I- jr $31 # I-

Part E (8 points) Assume $01 = P , $05 = A , $12 = J , $13 = K , and $14 = L and the letter array

is M[]. Write an expression (in terms of P , A , J , K , L , and M[] ) for when I-40 is executed.

4 problems, 7 pages Exam Two 12 April 2006

Part B (7 points) Given the state of the stack you computed in Part A, write a MIPS code

fragment to implement the statement from Baz: “Sum += Values[X];” Do not use absolute

addresses in your code; instead, access variables relative to the frame pointer.

instruction comment

Part C (7 points) Given the state of the stack you computed in Part A, write a MIPS code

fragment to implement the statement from Baz: “*End += 1;” Do not use absolute addresses in

your code; instead, access variables relative to the frame pointer.

instruction comment

4 problems, 7 pages Exam Two 12 April 2006

Problem 3 (3 parts, 22 points) Hash Tables

typedef struct Link { L-1 Memory

int Key; (^) L-2 Address Data int Value; L-3 6000 struct Link *Next; (^) L-4 6004 } Link; (^) L-5 6008 L-6 6012 typedef struct { (^) L-7 6016 Link *Buckets[NUMBUCKETS]; (^) L-8 6020 7084 Link *FreeLinks; (^) L-9 6024 int Size; L- ... } HashTable; (^) L-11 7056 6 L-12 7060 12 void Remove(HashTable *HT, int Key) { (^) L-13 7064 0 int Index; (^) L- ... Link *ThisLink; (^) L-15 7084 3 Link **TrailingPointer; (^) L-16 7088 17 int Hash(int Key); (^) L-17 7092 7120 void Print_Next_Link(Link *Next); (^) L- ... Index = Hash(Key); (^) L-19 7120 5 ThisLink = HT->Buckets[Index]; (^) L-20 7124 29 TrailingPointer = &(HT->Buckets[Index]); (^) L-21 7128 7056 L- ... while(ThisLink != NULL && ThisLink->Key != Key) { (^) L- TrailingPointer = &(ThisLink->Next); (^) L- ThisLink = ThisLink->Next;} (^) L- if (ThisLink != NULL) { (^) L- *TrailingPointer = ThisLink->Next; (^) L- ThisLink->Next = HT->FreeLinks; (^) L- HT->FreeLinks = ThisLink; (^) L- HT->Size -= 1;}}} (^) L-

Part A (10 points) Assume NUMBUCKETS = 7, Key = 5, HT = 6000, and Index = 5. Given

the snapshot of memory addresses shown to the right, what is the value of the following variables at each

of the indicated locations in the code:

Variable at L-22 at L-26 at L-

ThisLink

TrailingPointer

Part B (6 points) What list operation does line L-27 perform?

Part C (6 points) Removing which lines of code would cause a memory leak? Explain why.

4 problems, 7 pages Exam Two 12 April 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 + (1004) branch if not equal bne $1,$2,100 (^) if ($1 ≠ $2), PC = PC + 4 + (1004) jump jump j 10000 PC = 10000* jump register jr $31 PC = $ jump and link jal 10000 $31 = PC + 4; PC = 10000*