Question
Enter the C program in Listing 13.2.1. Using the -S compiler option, compile it with differing levels of optimization, i.e., -O1, -O2, -O3, and discuss
Enter the C program in Listing 13.2.1. Using the -S compiler option, compile it with differing levels of optimization, i.e., -O1, -O2, -O3, and discuss the assembly language that is generated. Compare the results with my solution in Listing 13.2.6. Is the optimized code easier or more difficult to read?
Listing 13.2.1 Code:
/* nineInts1.c
* Declares and adds nine integers.
* 2017-09-29: Bob Plantz
*/
#include
#include "sumNine1.h"
int main(void)
{
int total;
int a = 1;
int b = 2;
int c = 3;
int d = 4;
int e = 5;
int f = 6;
int g = 7;
int h = 8;
int i = 9;
total = sumNine(a, b, c, d, e, f, g, h, i);
printf("The sum is %i ", total);
return 0;
}
Listing 13.2.1 Sum the digits 0-9
Calls the function sumNine, showing the passing of nine arguments in C
Code in Listing 13.2.6.
/* sumNine1.c
* Computes sum of nine integers.
* 2017-09-29: Bob Plantz
*/
#include
#include "sumNine1.h"
int sumNine(int one, int two, int three, int four, int five,
int six, int seven, int eight, int nine)
{
int x;
x = one + two + three + four + five + six
+ seven + eight + nine;
return x;
}
Listing 13.2.3 Implementation file for sumNine function, which computes the integer sum of its nine arguments. (C)
Please explain thorougly and explain the differences between the code. Also is the code easier to read or more difficult and explain the answer.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started