


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!



if (a <= 5) b = c โ a - 25; else c = a/5; a = b + c;
addi $4, $0, 5 slt $5, $4, $1 Is 5 < a? bne $5, $0, Else If so, branch to Else sub $6, $3, $1 $6: c-a addi $2, $6, -25 b = c-a- j Continue Else: div $1, $4 Lo = a/ mflo $3 c = a/ Continue: add $1, $2, $3 a = b + c
.data V: .word 33, 44, 55, -9999, 100, 3, 22 .text Start: addi $2, $0, 0 # sum = 0; addi $5, $0, 0 # i = 0; lw $3, V($5) # elt = V[i]; addi $4, $0, - Loop: add $2, $2, $ addi $5, $5, 1 sll $1, $5, 2 lw $3, V($1) bne $3, $4, Loop div $2, $5 # Lo = sum/I; mflo $6 # $6 = avg; jr $
sum = 0; i = 0; elt = V[0];
do { sum += elt; i++; elt = V[i]; } while (elt != -9999);
avg = sum/i;
Part A (10 points) Partition the following MIPS code into basic blocks. For each basic block, fill in a box to the right with the address range of the instructions in the basic block. For example, if instructions at addresses 2000 through 2004 form a basic block, write โ2000-2004โ in a box. Fill in one box for each basic block. You may not need to use all of the boxes. Box B1 has already been filled in as an example.
1000 Minmax: addi $4, $0, 396 1004 lw $1, Array($4) 1008 lw $2, Array($4) 1012 Loop: lw $3, Array($4) 1016 slt $5, $3, $ 1020 beq $5, $0, Skip 1024 add $1, $3, $ 1028 Skip1: slt $5, $2, $ 1032 beq $5, $0, Skip 1036 add $2, $3, $ 1040 Skip2: addi $4, $4, - 1044 slt $5, $4, $ 1048 beq $5, $0, Loop 1052 jr $
Part B (15 points) Draw the control flow graph of the MIPS code in Part A, using the boxes you filled in. Label the edges of the control flow graph with โTโ and โFโ where appropriate. You do not need to fill in the boxes with addresses or instructions. The box B1 is already placed below to get you started.
T
F
T
F
F T
int Array1[15]; W = Array1[X];
Label Instruction Comment
int Array2[10][50]; W = Array2[Y][X];
Label Instruction Comment
int Array3[100][20][30]; W = Array3[Z][Y][X];
Label Instruction Comment