EXERCISES

  1. Make a list of all the programming languages that you can find and make a table for them indicating (i) if they are interpreted, compiled or part-compiled, (ii) the platforms on which available and (iii) application areas in which used. Do not forget languages for pictures generation (e.g. povray), printing (e.g. postscript), web (e.g. HTML, Javascript), etc. After you have made this table, compare it with Fig. 1.1.
  2. Certain properties of a programming language may require that the only way to get the code written in it be executed is by interpretation. In other words, compilation to a native machine code of a traditional CPU is not possible. What are these properties? Try to investigate in as much detail as you can. [Hint: Consider the way an interpreter executes a code and the way a compiled program is executed.]
  3. Look at source optimisel.c. Study optimize10.s, optimize100.s, optimize101.s, optimize102.s, optimize103.s, optimize103s.s. Which of these optimizations will be unacceptable in some applications or situations?
  4. Obtain details of METAFONT and METAPOST languages from Internet and study the basic objects, operations and functions provided in them.
  5. Portability of a program is said to be a desirable feature made available by an HLL. What issues can arise in making a program truly portable, i.e. one should be able to compile it and successfully execute it on any family of CPU?
  6. Suresh wrote the following small program in C, to find out execution speed of a particular CPU:
    #include <stdio.h>
    int main(){
      int i, a;
      for(i = 0; i<100000000; i++){
        a = 1;
      }
    }
    

He compiled it normally using gcc testopt.c −o testopt, executed it and got a running-time estimate of 0.288 s on an average. Then he recompiled it with gcc −03 testopt.c −o testopt (i.e. level 3 optimization) and got a running-time estimate of 0.003 s on an average. Surprised at this large reduction in time, he obtained the assembly language output for both the versions of translation:

# unoptimized
main:
      leal   4(%esp), %ecx
      andl   $−16, %esp
      pushl  -4(%ecx)
      pushl  %ebp
      movl   %esp, %ebp
      pushl  %ecx
      subl   $16, %esp
#----------------------------------------------
      movl   $0, −12(%ebp)
      jmp    .L2
.L3:
      movl   $1, -8(%ebp)
      incl   −12(%ebp)
.L2:
      cmpl   $99999999, −12(%ebp)
      jle    .L3
#----------------------------------------------
      addl   $16, %esp
      popl   %ecx
      popl   %ebp
      leal   −4(%ecx), %esp
      ret

# optimized
main:
      leal   4(%esp), %ecx
      andl   $−16, %esp
      pushl  -4(%ecx)
      pushl  %ebp
      movl   %esp, %ebp
      pushl  %ecx
#-----------------------------------------------
      popl   %ecx
      popl   %ebp
      leal   −4(%ecx), %esp
      ret

Comparing the two codes he found that the loop forming instructions, marked by two horizontal lines in the unoptimized code, were completely missing in the optimized code. Also, the local variables i and a were not created. What was going on?

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.26.221