Machine-translated by Google. Questions are authored in English.
Top

Discussion

Consider the following pseudo-code.

L1: t1 = −1
L2: t2 = 0
L3: t3 = 0
L4: t4 = 4 * t3
L5: t5 = 4 * t2
L6: t6 = t5 * M
L7: t7 = t4 + t6
L8: t8 = a[t7]
L9: if t8 \(\lt\)= max goto L11
L10: t1 = t8
L11: t3 = t3 + 1
L12: if t3 \(\lt\) M goto L4
L13: t2 = t2 + 1
L14: if t2 \(\lt\) N goto L3
L15: max = t1

Which one of the following options CORRECTLY specifies the number of basic blocks and the number of instructions in the largest basic block, respectively ?

  • A.6 and 6
  • B.6 and 7
  • C.7 and 7
  • D.7 and 6

Answer: D

There are 7 basic blocks, and the largest has 6 instructions.

Leaders are the first statement, every jump target and every statement after a jump. That gives L1, the targets L3, L4 and L11, and the statements after the conditional jumps, L10, L13 and L15. The blocks are:

  • L1-L2 (2)
  • L3 (1)
  • L4-L9 (6)
  • L10 (1)
  • L11-L12 (2)
  • L13-L14 (2)
  • L15 (1)

So 7 blocks, the largest L4 to L9 with 6 instructions. Missing the leader at L3 (a jump target) gives 6 blocks with a 7-instruction largest block; missing L10 merges it into the L4 block.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.