Docsity

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

Toggle sidebar
bg1
ECE 3035 B 12:00pm Computing Mechanisms Spring 2005
4 problems, 4 pages Exam One Solution 16 February 2005
Problem 1 (2 parts, 25 points) VotingMap Implementation
Consider the following fragment from the VotingMap baseline implementation:
slt $1, $3, $4
bne $1, $0, GBtest
slt $1, $3, $5
bne $1, $0, Bwinner
lui $3, 255
beq $0, $0, Update
Bwinner: addi $3, $0, 255
beq $0, $0, Update
GBtest: slt $1, $4, $5
bne $1, $0, Bwinner
ori $3, $0, 65280
Update: sw $3, Array($2)
Part A (15 points) Draw the flow diagram for the fragment above. Be sure to label blocks with
the corresponding code from the fragment.
TF
$3 >= $5
TF
$3 >= $4
FT
$4 >= $5
Red 16M Blue 255 Green 64K
sw result
Part B (10 points) Now re-express the fragment above as a C fragment. Assume R is in $3, G is
in $4, B is in $5, and N is in $2. Further assume that Array is an integer array.
if (R >= G)
if (R >= B)
Result = 16,711,680; /* Red wins */
else
Result = 255; /* Blue wins */
else if (G >= B)
Result = 65280; /* Green wins */
else
Result = 255; /* Blue wins */
Array[N] = Result;
1
pf3
pf4

Partial preview of the text

Download Exam Solutions for ECE 3035 Computing Mechanisms - Spring 2005 and more Exams Electrical and Electronics Engineering in PDF only on Docsity!

4 problems, 4 pages Exam One Solution 16 February 2005

Problem 1 (2 parts, 25 points) VotingMap Implementation

Consider the following fragment from the VotingMap baseline implementation: slt $1, $3, $ bne $1, $0, GBtest slt $1, $3, $ bne $1, $0, Bwinner lui $3, 255 beq $0, $0, Update Bwinner: addi $3, $0, 255 beq $0, $0, Update GBtest: slt $1, $4, $ bne $1, $0, Bwinner ori $3, $0, 65280 Update: sw $3, Array($2) Part A (15 points) Draw the flow diagram for the fragment above. Be sure to label blocks with the corresponding code from the fragment.

T F

T F

F T

Red 16M Blue 255 (^) Green 64K

sw result

Part B (10 points) Now re-express the fragment above as a C fragment. Assume R is in $3, G is in $4, B is in $5, and N is in $2. Further assume that Array is an integer array.

if (R >= G) if (R >= B) Result = 16,711,680; /* Red wins / else Result = 255; / Blue wins / else if (G >= B) Result = 65280; / Green wins / else Result = 255; / Blue wins */ Array[N] = Result;

4 problems, 4 pages Exam One Solution 16 February 2005

Problem 2 (2 parts, 31 points) Array and Pointers

Part A (15 points) Write the MIPS code implementation of the dynamically allocated array access below. 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 $2 and the indexed memory location.

int Array[8][12][4]; /* array declaration */

Array[A][B][C]= 375; /* implement this */ label instruction comment addi $1, $0, 48 load subarray size

mul $1, $4 A * 48

mflo $2 starting EA

sll $1, $5, 2 B * 4

add $2, $2, $1 add column offset to EA

add $2, $2, $6 add row offset

sll $2, $2, 2 multiple EA by word size, 4

add $2, $3, $2 add base address

addi $1, $0, 375 load constant

sw $1, 0($2) store 375 at Array[A][B][C]

Part B (16 points) The following static variables are allocated in memory beginning at address

  1. Determine the numerical values for the following expressions.

int A = 13; int *B = &A; int C[10] = {00, 11, 22, 33, 44, 55, 66, 77, 88, 99};

B 5000 *B 13 &B 5004

C 5008 C[5] 55 &(C[5]) 5028

4 problems, 4 pages Exam One Solution 16 February 2005

Problem 4 (1 part, 15 points) C Code

Write a C code fragment that best expresses the following control flow diagram.

N == 5

T F

N == 2

T F

N == 3

T F

N == 4

T F

A = 5*D

C = 4+D

A = 3/B

C = 9-B

A = B+D

switch (N) { case 2: A = 3 / B; case 3: C = 4 + D; break; case 4: 5 * D; break; case 5: C = 9 โ€“ B; default: A = B + D; }