


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



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-
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
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); }