Can anyone help me with my assignment please. thank you
Consider the following function that forms part of a C program that has
been written to measure the execution time of a simple arithmetic
statement like sum = sum + increment;
long sumLoop(long increment, long iterations)
{
long i, sum=0;
for (i=0 ; i < iterations ; i++) {
sum = sum + increment;
}
return (sum);
}
The following (numbered) lines of IA-32 (in GAS format) assembly
language corresponding to the above function have been generated
when the C program was compiled without optimisation:
10 sumLoop:
11 pushl %ebp
12 movl %esp, %ebp
13 subl $8, %esp
14 movl $0, -8(%ebp)
15 movl $0, -4(%ebp)
16 .L7:
17 movl -4(%ebp), %eax
18 cmpl 12(%ebp), %eax
19 jl .L10
20 jmp .L8
21 .L10:
22 movl 8(%ebp), %eax
23 leal -8(%ebp), %edx
24 addl %eax, (%edx)
25 leal -4(%ebp), %eax
26 incl (%eax)
27 jmp .L7
28 .L8:
29 movl -8(%ebp), %eax
30 leave
31 ret
Where appropriate please refer to these corresponding line number(s)
in your answers to the following questions:
(a) Explain the purpose and/or operation of these assembly language
statements in the context of this C function. Little credit will be given to
answers that merely repeat what is obvious from each statement. For
example, don't answer "pushes register ebp onto the stack" for line 11.
(10 marks)
(b) Outline a technique that a C programmer might use in an attempt to
measure the execution time of a single sum = sum + increment;
statement with a high degree of accuracy. Identify the issues in the
technique you propose that may lead to inaccuracies in timing and
discuss briefly how you would overcome these.
(5 marks)
© When the program is recompiled with optimisation (the –O3 compiler
switch) the programmer discovers that the sumLoop () function runs
faster and that the execution time of a sum = sum + increment;
statement drops to 1 nanosecond in the optimised code from the
original measurement of 5 nanoseconds in the non-optimised version
of the program. Give an explanation of the optimisations that are likely
to have been made by the compiler in order to achieve this fivefold
improvement in performance and compare and contrast these
optimisations with the original assembly code in the above listing.
(5 marks)