Docsity

Exam Solutions for ECE 3035B Spring 2006 - Computing Mechanisms, Exams of Electrical and Electronics Engineering

Toggle sidebar
bg1
ECE 3035B 1: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 addi $6, $1, 4096 I-1
1004 L1: lbu $7, 0($1) I-2
1008 sub $8, $7, $5 I-3
1012 slt $9, $8, $0 I-4
1016 beq $9, $0, L2 I-5
1020 sub $8, $0, $8 I-6
1024 L2: lbu $7, 1($1) I-7
1028 sub $7, $7, $4 I-8
1032 slt $9, $7, $0 I-9
1036 beq $9, $0, L3 I-10
1040 sub $7, $0, $7 I-11
1044 L3: add $8, $8, $7 I-12
1048 lbu $7, 2($1) I-13
1052 sub $7, $7, $3 I-14
1056 slt $9, $7, $0 I-15
1060 beq $9, $0, L4 I-16
1064 sub $7, $0, $7 I-17
1068 L4: add $8, $8, $7 I-18
1072 slti $9, $8, 49 I-19
1074 beq $9, $0, L5 I-20
1078 sw $2, 0($1) I-21
1082 L5: addi $1, $1, 4 I-22
1086 bne $1, $6, L1 I-23
Part 1.A (10 points) Consider instructions I-7 – I-12 in the assembly fragment above. If $1 = X, $4 = Y,
and $8 = Z, write the expression (in C) representing the value left in $8 when I-12 completes.
Result (left in $8) = Z + abs(X8-15 – Y)
Part 1.B (5 points) What how many iterations of I-2 – I-23 are performed when this fragment executes?
# of iterations = 1024
Part 1.C (5 points) Describe the conditions when instruction I-21 is executed. Include the impact of the
entire fragment; not just the predicate computation and branch (i.e., a high-level description).
If the sum of absolute differences of the 3 bytes of X compared
with the reference RGB (in $3, $4, and $5) is < 49, replace X with $2
(the reference color).
pf3
pf4

Partial preview of the text

Download Exam Solutions for ECE 3035B Spring 2006 - Computing Mechanisms 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 addi^ $6, $1, 4096^ I- 1004 L1: lbu $7, 0($1) (^) I- 1008 sub $8, $7, $5 I- 1012 slt $9, $8, $0 (^) I- 1016 beq $9, $0, L2 I- 1020 sub $8, $0, $8 (^) I- 1024 L2: lbu $7, 1($1) (^) I- 1028 sub^ $7, $7, $4^ I- 1032 slt $9, $7, $0 (^) I- 1036 beq $9, $0, L3 I- 1040 sub $7, $0, $7 (^) I- 1044 L3: add $8, $8, $7 (^) I- 1048 lbu $7, 2($1) (^) I- 1052 sub $7, $7, $3 (^) I- 1056 slt^ $9, $7, $0^ I- 1060 beq $9, $0, L4 (^) I- 1064 sub $7, $0, $7 I- 1068 L4: add $8, $8, $7 (^) I- 1072 slti $9, $8, 49 (^) I- 1074 beq^ $9, $0, L5^ I- 1078 sw $2, 0($1) (^) I- 1082 L5: addi $1, $1, 4 I- 1086 bne $1, $6, L1 (^) I-

Part 1.A (10 points) Consider instructions I-7 – I-12 in the assembly fragment above. If $1 = X, $4 = Y,

and $8 = Z, write the expression (in C) representing the value left in $8 when I-12 completes.

Result (left in $8) = Z + abs(X8-15 – Y)

Part 1.B (5 points) What how many iterations of I-2 – I-23 are performed when this fragment executes?

# of iterations = 1024

Part 1.C (5 points) Describe the conditions when instruction I-21 is executed. Include the impact of the

entire fragment; not just the predicate computation and branch (i.e., a high-level description).

If the sum of absolute differences of the 3 bytes of X compared

with the reference RGB (in $3, $4, and $5) is < 49, replace X with $

(the reference color).

4 problems, 6 pages Exam One Solutions 17 February 2006

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

Part 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 = 1.5; double *B = &A; double *C = B; double D = *C; char E[25]= “Hello ECE3035!”; int F[5] = {12, 66, 96, 32, 49};

C 5000 &C 5012 D 1.

E 5024 &E[5] 5029 &(F[2]) 5060

Part 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[6][3][4]; / array declaration /

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

Label Instruction Comment addi $1, $0, 12 # LxLy mult $4, $1 # ALxLy mflo $ sll $2, $5, 2 # 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, 123 # value to store sw $1, 0($2) # store 123 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

F T

Y < K

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

X = 0;

printf(”Processed %d values.\n”, YXN);

X < I F T

Value = 0; N = 0;

F T

N < J

Value += A[X][N] * B[N][Y]; N++;

C[X][Y] = Value; X++;

Y++;

Fill in the body of the subroutine give below with C code that is equivalent to the control flow graph representation to the left. For full credit, be sure to use the appropriate C construct for each loop depending on whether the loop is sentinel-controlled or counter- controlled.

void Foo(int I, int J, int K, int A[][J], int B[][K], int C[][K]) { int X, Y, N, Value; for (Y=0; Y<K; Y++) { for (X=0; X<I; X++) { Value = 0; for (N=0; N<J; N++){ Value += A[X][N] * B[N][Y];} C[X][Y] = Value; } } printf(“Processed %d values.\n”, YXN); }