


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 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-
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
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
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;}
Y < NumRows
int X, Y, Value, NumVals = 0; Y = 0;
return NumVals;
X < NumCols
fscanf(FP, โ%dโ, &Value); Array[Y][X] = Value; NumVals++; X++;