Docsity

Exam 1 Solutions - Mechanisms-Computing Systems | ECE 3035, Exams of Electrical and Electronics Engineering

Toggle sidebar
bg1
ECE 3035A 12:00pm Computing Mechanisms Spring 2006
4 problems, 6 pages Exam One Solutions 17 February 2006
1
Problem 1 (3 parts, 20 points) Understanding Project Baselines
1000 L1: addi $4, $4, -1 I-1
1004 add $1, $0, $0 I-2
1008 add $6, $0, $8 I-3
1012 L2: addi $6, $6, -1 I-4
1016 mult $4, $8 I-5
1020 mflo $2 I-6
1024 add $2, $2, $6 I-7
1028 sll $2, $2, 2 I-8
1032 lw $2, A($2) I-9
1036 mult $6, $9 I-10
1040 mflo $3 I-11
1044 add $3, $3, $5 I-12
1048 sll $3, $3, 2 I-13
1052 lw $3, B($3) I-14
1056 mult $2, $3 I-15
1060 mflo $2 I-16
1064 add $1, $1, $2 I-17
1068 bne $6, $0, L2 I-18
Part 1.A (10 points) Consider instructions I-10 โ€“ I-14 in the assembly fragment above. If $5 = Y, $6 = N,
and $9 = k, write the expression (in C) representing the value left in $3 when I-14 completes.
Result (left in $3) = B[N][Y]
Part 1.B (5 points) What input to this entire fragment determines the number of iterations of I-4 โ€“ I-18?
Input register to determine # of iterations = $8
Part 1.C (5 points) This fragment computes the core operation of what larger mathematical computation?
Matrix Multiplication
pf3
pf4

Partial preview of the text

Download Exam 1 Solutions - Mechanisms-Computing Systems | ECE 3035 and more Exams Electrical and Electronics Engineering in PDF only on Docsity!

4 problems, 6 pages Exam One Solutions 17 February 2006

Problem 1 (3 parts, 20 points) Understanding Project Baselines

1000 L1: addi^ $4, $4, -1^ I- 1004 add $1, $0, $0 (^) I- 1008 add $6, $0, $8 I- 1012 L2: addi $6, $6, -1 (^) I- 1016 mult $4, $8 I- 1020 mflo $2 (^) I- 1024 add $2, $2, $6 (^) I- 1028 sll^ $2, $2, 2^ I- 1032 lw $2, A($2) (^) I- 1036 mult $6, $9 I- 1040 mflo $3 (^) I- 1044 add $3, $3, $5 (^) I- 1048 sll $3, $3, 2 (^) I- 1052 lw $3, B($3) (^) I- 1056 mult^ $2, $3^ I- 1060 mflo $2 (^) I- 1064 add $1, $1, $2 I- 1068 bne $6, $0, L2 (^) I-

Part 1.A (10 points) Consider instructions I-10 โ€“ I-14 in the assembly fragment above. If $5 = Y, $6 = N,

and $9 = k, write the expression (in C) representing the value left in $3 when I-14 completes.

Result (left in $3) = B[N][Y]

Part 1.B (5 points) What input to this entire fragment determines the number of iterations of I-4 โ€“ I-18?

Input register to determine # of iterations = $

Part 1.C (5 points) This fragment computes the core operation of what larger mathematical computation?

Matrix Multiplication

4 problems, 6 pages Exam One Solutions 17 February 2006

Problem 2 (2 parts, 30 points) Pointers and Arrays

Part 2.A (18 points) The following static variables are allocated in memory beginning at address

  1. Determine the numerical values for the following expressions.

double A = 3.1416; int B = 20; int *C = &B; int D = *C; char E[25]= โ€œHello ECE3035!โ€; int F[5] = {12, 66, 96, 32, 49};

&B 5008 C 5008 D 20

E 5020 &E[7] 5027 &(F[1]) 5052

Part 2.B (12 points) Write the MIPS code implementation of the dynamically allocated array

access below in the smallest number of instructions. A pointer to the array (declared below) is

stored in $3. Variables A, B, and C reside in $4, $5, and $6 respectively. Modify only $1 and $

and the indexed memory location.

int Array[8][5][16]; / array declaration /

Array[A][B][C]= 99; / implement this /

Label Instruction Comment addi $1, $0, 80 # LxLy mult $4, $1 # ALxLy mflo $ sll $2, $5, 4 # BLx add $2, $2, $1 # ALxLy + BLx add $2, $2, $6 # ALxLy + BLx + C sll $2, $2, 2 # byte offset add $2, $2, $3 # + base of array addi $1, $0, 99 # value to store sw $1, 0($2) # store 99 at Array[A][B][C]

4 problems, 6 pages Exam One Solutions 17 February 2006

Problem 4 (1 part, 21 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;}

F T

Y < NumRows

int X, Y, Value, NumVals = 0; Y = 0;

X = 0;

return NumVals;

X < NumCols

F T

fscanf(FP, โ€œ%dโ€, &Value); Array[Y][X] = Value; NumVals++; X++;

Y++;