SlideShare une entreprise Scribd logo
1  sur  11
20145-5SumII_CSC407_assign1.html
CSC 407: Computer Systems II: 2015 Summer II, Assignment
#1
Last Modified 2015 July 21Purpose:
To go over issues related to how the compiler and the linker
serve you, the programmer.
Computing
Please ssh into ctilinux1.cstcis.cti.depaul.edu, or use your own
Linux machine.
Compiler optimization (45 Points)
Consider the following program.
/* q1.c
*/
#include <stdlib.h>
#include <stdio.h>
#define unsigned int uint
#define LENGTH ((uint) 512*64)
int initializeArray(uint len,
int* intArray
)
{
uint i;
for (i = 0; i < len; i++)
intArray[i] = (rand() % 64);
}
uint countAdjacent (int maxIndex,
int* intArray,
int direction
)
{
uint i;
uint sum = 0;
for (i = 0; i < maxIndex; i++)
if ( ( intArray[i] == (intArray[i+1] + direction) ) &&
( intArray[i] == (intArray[i+2] + 2*direction) )
)
sum++;
return(sum);
}
uint funkyFunction (uint len,
int* intArray
)
{
uint i;
uint sum = 0;
for (i = 0; i < len-1; i++)
if ( (i % 8) == 0x3 )
sum += 7*countAdjacent(len-2,intArray,+1);
else
sum += 17*countAdjacent(len-2,intArray,-1);
return(sum);
}
int main ()
{
int* intArray = (int*)calloc(LENGTH,sizeof(int));
initializeArray(LENGTH,intArray);
printf("funkyFunction() ==
%dn",funkyFunction(LENGTH,intArray));
free(intArray);
return(EXIT_SUCCESS);
}
(8 Points) Compile it for profiling but with no extra
optimization with:
$ gcc -o q1None -pg q1.c # Compiles q1.c to write q1None to
make profile info
$ ./q1None # Runs q1None
$ gprof q1None # Gives profile info on q1None
Be sure to scroll all the way to the top of gprof output!
What are the number of self seconds taken by:
FunctionSelf
secondsinitializeBigArray()__________countAdjaceent()______
____funkyFunction()__________
(8 Points)
How did it do the operation (i % 8) == 0x3?
Was it done as a modulus (the same as an expensive
division, but returns the remainder instead of the quotient) or
something else?
Show the assembly language for this C code
using gdb to dissassemble
funkyFunction() of q1None.
Hint: do:
$ gdb q1None
. . .
(gdb) disass funkyFunction
Dump of assembler code for function funkyFunction:
. . .
and then look for the code that sets up the calls to
countAdjacent().
The (i % 8) == 0x3 test is done before either
countAdjacent() call.
(8 Points) Compile it for profiling but with optimization
with:
$ gcc -o q1Compiler -O1 -pg q1.c # Compiles q1.c to write
q1Compiler to make profile info
$ ./q1Compiler # Runs q1Compiler
$ gprof q1Compiler # Gives profile info on
q1Compiler
What are the number of self seconds taken by:
FunctionSelf
secondsinitializeBigArray()__________countAdjacent()_______
___funkyFunction()__________(8 Points) Use gdb to
dissassemble countAdjacent() of both q1None and q1Compiler.
Don't try to understand all the code but in general how
did the optimizer make q1Compiler's countAdjacent() faster
than q1None's?
Give a specific example by comparing both assembly
codes.
(8 Points) One optimization the compiler may not have
made would be do the two countAdjacent() calls once each
before the loop in funkyFunction(), put them in variables, and
then use those variables in the loop.
Re-write the code this way:
. . .
uint i;
uint sum = 0;
uint countUp = 7*countAdjacent(len-2,intArray,+1);
uint countDn = 17*countAdjacent(len-2,intArray,-1);
for (i = 0; i < len-1; i++)
if ( (i % 8) == 0x3 )
sum += countUp;
else
sum += countDn;
Compile it for profiling again with optimization with:
$ gcc -o q1Programmer -O1 -pg q1.c # Compiles q1.c to write
q1Programmer to make profile info
$ ./q1Programmer # Runs q1Programmer
$ gprof q1Programmer # Gives profile info on
q1Programmer
What are the number of self seconds taken by:
FunctionSelf
secondsinitializeBigArray()__________countAdjacent()_______
___funkyFunction()__________(5 Points) Which optimizations
ought to be done by the compiler?
Which optimizations ought to be done by the
programmer?
Linker operation (55 Points total)
The program file p1.c below compiles under Linux to create
an object file p1.o.
It is to be linked with another file p2.o to create a running
program, whole.
/* p1.c
*/
#include <stdlib.h>
#include <stdio.h>
//
// Declarations go here:
//
// PURPOSE: To hold the length of the array pointed to by
'intArray'.
extern int length;
// PURPOSE: To hold the array of integers.
extern int* intArray;
// PURPOSE: To hold the maximum value that may place in
array 'intArray'.
extern int maxRandVal;
// PURPOSE: To:
// (1) have user enter 'length' (by calling 'enterValue()'),
// (2) have user enter 'maxRandVal' (by calling
'enterValue()'),
// (3) define 'intArray' (say 'intArray
=(int*)calloc(length,sizeof(int))')
// (4) fill 'intArray' with random numbers between 0-
'maxRandVal'
// (use expression '(rand() % (maxRandVal+1))')
// No parameters. No return value.
extern void createArray ();
// PURPOSE: To print the values in 'intArray[]'. No
parameters. No return
// value.
extern void printArray ();
//
// Function and variables go here:
//
// PURPOSE: To hold the minimum value for 'length'.
int minArrayLen = 1;
// PURPOSE: To hold the maximum value for 'length'.
int maxArrayLen = 256;
// PURPOSE: To hold the maximum value for 'maxRandVal'.
int maxMaxRandVal = 256;
// PURPOSE: To hold the length of C-string 'line'.
#define MAX_LINE 256
// PURPOSE: To hold the a C-string.
char line[MAX_LINE];
// PURPOSE: To have the user enter the variable pointed to by
'valuePtr',
// which must be between 'min' and 'max', and which is
described by
// '*descriptionPtr'. No parameters. No return value.
void enterValue (const char* descriptionPtr,
int min,
int max,
int* valuePtr
)
{
do
{
printf("Please enter the %s (%d-%d):
",descriptionPtr,min,max);
fgets(line,MAX_LINE,stdin);
*valuePtr = strtol(line,NULL,10);
}
while ( (*valuePtr < min) || (*valuePtr > max) );
}
// PURPOSE: To free 'intArray'. No parameters. No return
value.
//
void freeArray ()
{
free(intArray);
}
// PURPOSE: To define the array, print an array, and free the
array. No
// Ignores parameters. Returns 'EXIT_SUCCESS' to OS.
int main ()
{
createArray();
printArray();
freeArray();
return(EXIT_SUCCESS);
}
Sample output:[[email protected] Assign1]$ gcc -c p1.c
[[email protected] Assign1]$ gcc -c p2.c
[[email protected] Assign1]$ gcc -o whole p1.o p2.o
[[email protected] Assign1]$ ./whole
Please enter the array's length (1-256): 0
Please enter the array's length (1-256): 257
Please enter the array's length (1-256): 16
Please enter the maximum random value (1-256): 0
Please enter the maximum random value (1-256): 257
Please enter the maximum random value (1-256): 4
The array is:
intArray[0] = 3
intArray[1] = 1
intArray[2] = 2
intArray[3] = 0
intArray[4] = 3
intArray[5] = 0
intArray[6] = 1
intArray[7] = 2
intArray[8] = 4
intArray[9] = 1
intArray[10] = 2
intArray[11] = 2
intArray[12] = 0
intArray[13] = 4
intArray[14] = 3
intArray[15] = 1
[[email protected] Assign1]$
(30 Points) Write a program file p2.c that would compile to
p2.o, and would link with p1.o to create a legal running
program whole.
Important: Include your p2.c with your submission!
HINTS:
What does p1.c need that it does not define?Be sure to
extern any necessary functions with the same parameters as they
are declared.
What does p1.c define that p2.c would need?
Be sure to extern both such variable and function
symbols.
Create the individual object files and the complete
executable with:
linux> gcc -c p1.c # creates p1.o
linux> gcc -c p2.c # creates p2.o
linux> gcc p1.o p2.o -o whole # creates whole
linux> ./whole # runs whole
(5 Points) Use objdump (not gdb!) to disassemble both main()
and createArray() in whole.
Find the call to createArray() in main().
Show the math of how the number in that call instruction
is used to compute the address where createArray() actually is.
(5 Points) Which segment (that is: .text, .rodata, .data or
.bss) of p1.o has string constant
used in enterValue()'s printf() call?
Show this with objdump.
(5 Points) Can you find the memory for enterValue()'s
variable min using objdump?
If you can, use objdump to show where it is.
If you can't, tell why not.
(5 Points) Which segment of p2.o has the function
printArray()?
Show this with objdump.
(5 Points) It is rather inelegant for both p1.c and
p2.c to have the code:
// PURPOSE: To hold the length of C-string 'line'.
#define MAX_LINE 256
because if we decide to make a change we have to
remember to change all .c files.
Suggest a more elegant solution, one that C encourages.

Contenu connexe

Similaire à 20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx

The Ring programming language version 1.5.3 book - Part 91 of 184
The Ring programming language version 1.5.3 book - Part 91 of 184The Ring programming language version 1.5.3 book - Part 91 of 184
The Ring programming language version 1.5.3 book - Part 91 of 184Mahmoud Samir Fayed
 
The Ring programming language version 1.7 book - Part 87 of 196
The Ring programming language version 1.7 book - Part 87 of 196The Ring programming language version 1.7 book - Part 87 of 196
The Ring programming language version 1.7 book - Part 87 of 196Mahmoud Samir Fayed
 
JVM code reading -- C2
JVM code reading -- C2JVM code reading -- C2
JVM code reading -- C2ytoshima
 
The Ring programming language version 1.5.4 book - Part 82 of 185
The Ring programming language version 1.5.4 book - Part 82 of 185The Ring programming language version 1.5.4 book - Part 82 of 185
The Ring programming language version 1.5.4 book - Part 82 of 185Mahmoud Samir Fayed
 
Programming Fundamentals Functions in C and types
Programming Fundamentals  Functions in C  and typesProgramming Fundamentals  Functions in C  and types
Programming Fundamentals Functions in C and typesimtiazalijoono
 
Analysis of Haiku Operating System (BeOS Family) by PVS-Studio. Part 2
Analysis of Haiku Operating System (BeOS Family) by PVS-Studio. Part 2Analysis of Haiku Operating System (BeOS Family) by PVS-Studio. Part 2
Analysis of Haiku Operating System (BeOS Family) by PVS-Studio. Part 2PVS-Studio
 
C Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointC Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointJavaTpoint.Com
 
Modify this code to use multiple threads with the same data1.Modif.pdf
Modify this code to use multiple threads with the same data1.Modif.pdfModify this code to use multiple threads with the same data1.Modif.pdf
Modify this code to use multiple threads with the same data1.Modif.pdfmallik3000
 
The Ring programming language version 1.2 book - Part 59 of 84
The Ring programming language version 1.2 book - Part 59 of 84The Ring programming language version 1.2 book - Part 59 of 84
The Ring programming language version 1.2 book - Part 59 of 84Mahmoud Samir Fayed
 
C programming session 01
C programming session 01C programming session 01
C programming session 01Vivek Singh
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial javaTpoint s
 
The Ring programming language version 1.10 book - Part 97 of 212
The Ring programming language version 1.10 book - Part 97 of 212The Ring programming language version 1.10 book - Part 97 of 212
The Ring programming language version 1.10 book - Part 97 of 212Mahmoud Samir Fayed
 

Similaire à 20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx (20)

C introduction by piyushkumar
C introduction by piyushkumarC introduction by piyushkumar
C introduction by piyushkumar
 
The Ring programming language version 1.5.3 book - Part 91 of 184
The Ring programming language version 1.5.3 book - Part 91 of 184The Ring programming language version 1.5.3 book - Part 91 of 184
The Ring programming language version 1.5.3 book - Part 91 of 184
 
C tutorials
C tutorialsC tutorials
C tutorials
 
The Ring programming language version 1.7 book - Part 87 of 196
The Ring programming language version 1.7 book - Part 87 of 196The Ring programming language version 1.7 book - Part 87 of 196
The Ring programming language version 1.7 book - Part 87 of 196
 
JVM code reading -- C2
JVM code reading -- C2JVM code reading -- C2
JVM code reading -- C2
 
UNIT-II CP DOC.docx
UNIT-II CP DOC.docxUNIT-II CP DOC.docx
UNIT-II CP DOC.docx
 
The Ring programming language version 1.5.4 book - Part 82 of 185
The Ring programming language version 1.5.4 book - Part 82 of 185The Ring programming language version 1.5.4 book - Part 82 of 185
The Ring programming language version 1.5.4 book - Part 82 of 185
 
Programming Fundamentals Functions in C and types
Programming Fundamentals  Functions in C  and typesProgramming Fundamentals  Functions in C  and types
Programming Fundamentals Functions in C and types
 
Analysis of Haiku Operating System (BeOS Family) by PVS-Studio. Part 2
Analysis of Haiku Operating System (BeOS Family) by PVS-Studio. Part 2Analysis of Haiku Operating System (BeOS Family) by PVS-Studio. Part 2
Analysis of Haiku Operating System (BeOS Family) by PVS-Studio. Part 2
 
C Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointC Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpoint
 
Modify this code to use multiple threads with the same data1.Modif.pdf
Modify this code to use multiple threads with the same data1.Modif.pdfModify this code to use multiple threads with the same data1.Modif.pdf
Modify this code to use multiple threads with the same data1.Modif.pdf
 
The Ring programming language version 1.2 book - Part 59 of 84
The Ring programming language version 1.2 book - Part 59 of 84The Ring programming language version 1.2 book - Part 59 of 84
The Ring programming language version 1.2 book - Part 59 of 84
 
C programming session 01
C programming session 01C programming session 01
C programming session 01
 
Programming in C
Programming in CProgramming in C
Programming in C
 
CPP Homework Help
CPP Homework HelpCPP Homework Help
CPP Homework Help
 
GCC RTL and Machine Description
GCC RTL and Machine DescriptionGCC RTL and Machine Description
GCC RTL and Machine Description
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
 
Functions
FunctionsFunctions
Functions
 
Linux_C_LabBasics.ppt
Linux_C_LabBasics.pptLinux_C_LabBasics.ppt
Linux_C_LabBasics.ppt
 
The Ring programming language version 1.10 book - Part 97 of 212
The Ring programming language version 1.10 book - Part 97 of 212The Ring programming language version 1.10 book - Part 97 of 212
The Ring programming language version 1.10 book - Part 97 of 212
 

Plus de eugeniadean34240

I need a 7 pg research essay on the following   Select a real o.docx
I need a 7 pg research essay on the following   Select a real o.docxI need a 7 pg research essay on the following   Select a real o.docx
I need a 7 pg research essay on the following   Select a real o.docxeugeniadean34240
 
I need a 4-5 APA formatted paper with references that is clearly wri.docx
I need a 4-5 APA formatted paper with references that is clearly wri.docxI need a 4-5 APA formatted paper with references that is clearly wri.docx
I need a 4-5 APA formatted paper with references that is clearly wri.docxeugeniadean34240
 
I need a 3 page research paper on Title  Addictive being youn.docx
I need a 3 page research paper on Title  Addictive being youn.docxI need a 3 page research paper on Title  Addictive being youn.docx
I need a 3 page research paper on Title  Addictive being youn.docxeugeniadean34240
 
I need a 3 page double-spaced 12-point paper on Immunotherapy. the i.docx
I need a 3 page double-spaced 12-point paper on Immunotherapy. the i.docxI need a 3 page double-spaced 12-point paper on Immunotherapy. the i.docx
I need a 3 page double-spaced 12-point paper on Immunotherapy. the i.docxeugeniadean34240
 
I need a 2500 word essay on the 1st Battalion 7th Cavalry Regiment. .docx
I need a 2500 word essay on the 1st Battalion 7th Cavalry Regiment. .docxI need a 2500 word essay on the 1st Battalion 7th Cavalry Regiment. .docx
I need a 2500 word essay on the 1st Battalion 7th Cavalry Regiment. .docxeugeniadean34240
 
I need a 200-word paper that answers the following questions:D.docx
I need a 200-word paper that answers the following questions:D.docxI need a 200-word paper that answers the following questions:D.docx
I need a 200-word paper that answers the following questions:D.docxeugeniadean34240
 
i need a 2 page essay on LA crimes as it pertains to Rape you will h.docx
i need a 2 page essay on LA crimes as it pertains to Rape you will h.docxi need a 2 page essay on LA crimes as it pertains to Rape you will h.docx
i need a 2 page essay on LA crimes as it pertains to Rape you will h.docxeugeniadean34240
 
I need a 1 page professional bio. My cover letter and resume i.docx
I need a 1 page professional bio. My cover letter and resume i.docxI need a 1 page professional bio. My cover letter and resume i.docx
I need a 1 page professional bio. My cover letter and resume i.docxeugeniadean34240
 
I need 100 words response for this two discussion forum1 discu.docx
I need 100 words response for this two discussion forum1 discu.docxI need 100 words response for this two discussion forum1 discu.docx
I need 100 words response for this two discussion forum1 discu.docxeugeniadean34240
 
I need 200 words response for each discussion post.Guided Respon.docx
I need 200 words response for each discussion post.Guided Respon.docxI need 200 words response for each discussion post.Guided Respon.docx
I need 200 words response for each discussion post.Guided Respon.docxeugeniadean34240
 
I need 3 pages discussion for an intersection (Attached image).docx
I need 3 pages discussion for an intersection (Attached image).docxI need 3 pages discussion for an intersection (Attached image).docx
I need 3 pages discussion for an intersection (Attached image).docxeugeniadean34240
 
I need 1page write up on Hypothesis & Methods Proposal,Due on .docx
I need 1page write up on Hypothesis & Methods Proposal,Due on .docxI need 1page write up on Hypothesis & Methods Proposal,Due on .docx
I need 1page write up on Hypothesis & Methods Proposal,Due on .docxeugeniadean34240
 
I need 2-3 pages written about the sieve of Eratosthenes. Starti.docx
I need 2-3 pages written about the sieve of Eratosthenes. Starti.docxI need 2-3 pages written about the sieve of Eratosthenes. Starti.docx
I need 2-3 pages written about the sieve of Eratosthenes. Starti.docxeugeniadean34240
 
I need 120 words for each question. Please ensure to post individual.docx
I need 120 words for each question. Please ensure to post individual.docxI need 120 words for each question. Please ensure to post individual.docx
I need 120 words for each question. Please ensure to post individual.docxeugeniadean34240
 
I need 10-12 slides Presentation with detailed speaker notes. Instru.docx
I need 10-12 slides Presentation with detailed speaker notes. Instru.docxI need 10-12 slides Presentation with detailed speaker notes. Instru.docx
I need 10-12 slides Presentation with detailed speaker notes. Instru.docxeugeniadean34240
 
I N N O V A T I O N N E T W O R K , I N C . www.innone.docx
I N N O V A T I O N  N E T W O R K ,  I N C .   www.innone.docxI N N O V A T I O N  N E T W O R K ,  I N C .   www.innone.docx
I N N O V A T I O N N E T W O R K , I N C . www.innone.docxeugeniadean34240
 
I like to tie my learning to Biblical Principles. On Virtuous Le.docx
I like to tie my learning to Biblical Principles. On Virtuous Le.docxI like to tie my learning to Biblical Principles. On Virtuous Le.docx
I like to tie my learning to Biblical Principles. On Virtuous Le.docxeugeniadean34240
 
I just want one paragraph.!!C.W.Mills described ‘sociological im.docx
I just want one paragraph.!!C.W.Mills described ‘sociological im.docxI just want one paragraph.!!C.W.Mills described ‘sociological im.docx
I just want one paragraph.!!C.W.Mills described ‘sociological im.docxeugeniadean34240
 
i just need serious help answering the question. I have answered mos.docx
i just need serious help answering the question. I have answered mos.docxi just need serious help answering the question. I have answered mos.docx
i just need serious help answering the question. I have answered mos.docxeugeniadean34240
 
I Headnotes and indexes are copyrighted and may not be duplica.docx
I Headnotes and indexes are copyrighted and may not be duplica.docxI Headnotes and indexes are copyrighted and may not be duplica.docx
I Headnotes and indexes are copyrighted and may not be duplica.docxeugeniadean34240
 

Plus de eugeniadean34240 (20)

I need a 7 pg research essay on the following   Select a real o.docx
I need a 7 pg research essay on the following   Select a real o.docxI need a 7 pg research essay on the following   Select a real o.docx
I need a 7 pg research essay on the following   Select a real o.docx
 
I need a 4-5 APA formatted paper with references that is clearly wri.docx
I need a 4-5 APA formatted paper with references that is clearly wri.docxI need a 4-5 APA formatted paper with references that is clearly wri.docx
I need a 4-5 APA formatted paper with references that is clearly wri.docx
 
I need a 3 page research paper on Title  Addictive being youn.docx
I need a 3 page research paper on Title  Addictive being youn.docxI need a 3 page research paper on Title  Addictive being youn.docx
I need a 3 page research paper on Title  Addictive being youn.docx
 
I need a 3 page double-spaced 12-point paper on Immunotherapy. the i.docx
I need a 3 page double-spaced 12-point paper on Immunotherapy. the i.docxI need a 3 page double-spaced 12-point paper on Immunotherapy. the i.docx
I need a 3 page double-spaced 12-point paper on Immunotherapy. the i.docx
 
I need a 2500 word essay on the 1st Battalion 7th Cavalry Regiment. .docx
I need a 2500 word essay on the 1st Battalion 7th Cavalry Regiment. .docxI need a 2500 word essay on the 1st Battalion 7th Cavalry Regiment. .docx
I need a 2500 word essay on the 1st Battalion 7th Cavalry Regiment. .docx
 
I need a 200-word paper that answers the following questions:D.docx
I need a 200-word paper that answers the following questions:D.docxI need a 200-word paper that answers the following questions:D.docx
I need a 200-word paper that answers the following questions:D.docx
 
i need a 2 page essay on LA crimes as it pertains to Rape you will h.docx
i need a 2 page essay on LA crimes as it pertains to Rape you will h.docxi need a 2 page essay on LA crimes as it pertains to Rape you will h.docx
i need a 2 page essay on LA crimes as it pertains to Rape you will h.docx
 
I need a 1 page professional bio. My cover letter and resume i.docx
I need a 1 page professional bio. My cover letter and resume i.docxI need a 1 page professional bio. My cover letter and resume i.docx
I need a 1 page professional bio. My cover letter and resume i.docx
 
I need 100 words response for this two discussion forum1 discu.docx
I need 100 words response for this two discussion forum1 discu.docxI need 100 words response for this two discussion forum1 discu.docx
I need 100 words response for this two discussion forum1 discu.docx
 
I need 200 words response for each discussion post.Guided Respon.docx
I need 200 words response for each discussion post.Guided Respon.docxI need 200 words response for each discussion post.Guided Respon.docx
I need 200 words response for each discussion post.Guided Respon.docx
 
I need 3 pages discussion for an intersection (Attached image).docx
I need 3 pages discussion for an intersection (Attached image).docxI need 3 pages discussion for an intersection (Attached image).docx
I need 3 pages discussion for an intersection (Attached image).docx
 
I need 1page write up on Hypothesis & Methods Proposal,Due on .docx
I need 1page write up on Hypothesis & Methods Proposal,Due on .docxI need 1page write up on Hypothesis & Methods Proposal,Due on .docx
I need 1page write up on Hypothesis & Methods Proposal,Due on .docx
 
I need 2-3 pages written about the sieve of Eratosthenes. Starti.docx
I need 2-3 pages written about the sieve of Eratosthenes. Starti.docxI need 2-3 pages written about the sieve of Eratosthenes. Starti.docx
I need 2-3 pages written about the sieve of Eratosthenes. Starti.docx
 
I need 120 words for each question. Please ensure to post individual.docx
I need 120 words for each question. Please ensure to post individual.docxI need 120 words for each question. Please ensure to post individual.docx
I need 120 words for each question. Please ensure to post individual.docx
 
I need 10-12 slides Presentation with detailed speaker notes. Instru.docx
I need 10-12 slides Presentation with detailed speaker notes. Instru.docxI need 10-12 slides Presentation with detailed speaker notes. Instru.docx
I need 10-12 slides Presentation with detailed speaker notes. Instru.docx
 
I N N O V A T I O N N E T W O R K , I N C . www.innone.docx
I N N O V A T I O N  N E T W O R K ,  I N C .   www.innone.docxI N N O V A T I O N  N E T W O R K ,  I N C .   www.innone.docx
I N N O V A T I O N N E T W O R K , I N C . www.innone.docx
 
I like to tie my learning to Biblical Principles. On Virtuous Le.docx
I like to tie my learning to Biblical Principles. On Virtuous Le.docxI like to tie my learning to Biblical Principles. On Virtuous Le.docx
I like to tie my learning to Biblical Principles. On Virtuous Le.docx
 
I just want one paragraph.!!C.W.Mills described ‘sociological im.docx
I just want one paragraph.!!C.W.Mills described ‘sociological im.docxI just want one paragraph.!!C.W.Mills described ‘sociological im.docx
I just want one paragraph.!!C.W.Mills described ‘sociological im.docx
 
i just need serious help answering the question. I have answered mos.docx
i just need serious help answering the question. I have answered mos.docxi just need serious help answering the question. I have answered mos.docx
i just need serious help answering the question. I have answered mos.docx
 
I Headnotes and indexes are copyrighted and may not be duplica.docx
I Headnotes and indexes are copyrighted and may not be duplica.docxI Headnotes and indexes are copyrighted and may not be duplica.docx
I Headnotes and indexes are copyrighted and may not be duplica.docx
 

Dernier

Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 

Dernier (20)

Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 

20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx

  • 1. 20145-5SumII_CSC407_assign1.html CSC 407: Computer Systems II: 2015 Summer II, Assignment #1 Last Modified 2015 July 21Purpose: To go over issues related to how the compiler and the linker serve you, the programmer. Computing Please ssh into ctilinux1.cstcis.cti.depaul.edu, or use your own Linux machine. Compiler optimization (45 Points) Consider the following program. /* q1.c */ #include <stdlib.h> #include <stdio.h> #define unsigned int uint #define LENGTH ((uint) 512*64) int initializeArray(uint len, int* intArray ) { uint i;
  • 2. for (i = 0; i < len; i++) intArray[i] = (rand() % 64); } uint countAdjacent (int maxIndex, int* intArray, int direction ) { uint i; uint sum = 0; for (i = 0; i < maxIndex; i++) if ( ( intArray[i] == (intArray[i+1] + direction) ) && ( intArray[i] == (intArray[i+2] + 2*direction) ) ) sum++; return(sum); } uint funkyFunction (uint len, int* intArray ) { uint i; uint sum = 0; for (i = 0; i < len-1; i++) if ( (i % 8) == 0x3 ) sum += 7*countAdjacent(len-2,intArray,+1); else
  • 3. sum += 17*countAdjacent(len-2,intArray,-1); return(sum); } int main () { int* intArray = (int*)calloc(LENGTH,sizeof(int)); initializeArray(LENGTH,intArray); printf("funkyFunction() == %dn",funkyFunction(LENGTH,intArray)); free(intArray); return(EXIT_SUCCESS); } (8 Points) Compile it for profiling but with no extra optimization with: $ gcc -o q1None -pg q1.c # Compiles q1.c to write q1None to make profile info $ ./q1None # Runs q1None $ gprof q1None # Gives profile info on q1None Be sure to scroll all the way to the top of gprof output! What are the number of self seconds taken by: FunctionSelf secondsinitializeBigArray()__________countAdjaceent()______ ____funkyFunction()__________ (8 Points) How did it do the operation (i % 8) == 0x3? Was it done as a modulus (the same as an expensive division, but returns the remainder instead of the quotient) or something else? Show the assembly language for this C code
  • 4. using gdb to dissassemble funkyFunction() of q1None. Hint: do: $ gdb q1None . . . (gdb) disass funkyFunction Dump of assembler code for function funkyFunction: . . . and then look for the code that sets up the calls to countAdjacent(). The (i % 8) == 0x3 test is done before either countAdjacent() call. (8 Points) Compile it for profiling but with optimization with: $ gcc -o q1Compiler -O1 -pg q1.c # Compiles q1.c to write q1Compiler to make profile info $ ./q1Compiler # Runs q1Compiler $ gprof q1Compiler # Gives profile info on q1Compiler What are the number of self seconds taken by: FunctionSelf secondsinitializeBigArray()__________countAdjacent()_______ ___funkyFunction()__________(8 Points) Use gdb to dissassemble countAdjacent() of both q1None and q1Compiler. Don't try to understand all the code but in general how
  • 5. did the optimizer make q1Compiler's countAdjacent() faster than q1None's? Give a specific example by comparing both assembly codes. (8 Points) One optimization the compiler may not have made would be do the two countAdjacent() calls once each before the loop in funkyFunction(), put them in variables, and then use those variables in the loop. Re-write the code this way: . . . uint i; uint sum = 0; uint countUp = 7*countAdjacent(len-2,intArray,+1); uint countDn = 17*countAdjacent(len-2,intArray,-1); for (i = 0; i < len-1; i++) if ( (i % 8) == 0x3 ) sum += countUp; else sum += countDn; Compile it for profiling again with optimization with: $ gcc -o q1Programmer -O1 -pg q1.c # Compiles q1.c to write q1Programmer to make profile info $ ./q1Programmer # Runs q1Programmer $ gprof q1Programmer # Gives profile info on q1Programmer What are the number of self seconds taken by: FunctionSelf secondsinitializeBigArray()__________countAdjacent()_______ ___funkyFunction()__________(5 Points) Which optimizations ought to be done by the compiler?
  • 6. Which optimizations ought to be done by the programmer? Linker operation (55 Points total) The program file p1.c below compiles under Linux to create an object file p1.o. It is to be linked with another file p2.o to create a running program, whole. /* p1.c */ #include <stdlib.h> #include <stdio.h> // // Declarations go here: // // PURPOSE: To hold the length of the array pointed to by 'intArray'. extern int length; // PURPOSE: To hold the array of integers. extern int* intArray; // PURPOSE: To hold the maximum value that may place in array 'intArray'. extern int maxRandVal;
  • 7. // PURPOSE: To: // (1) have user enter 'length' (by calling 'enterValue()'), // (2) have user enter 'maxRandVal' (by calling 'enterValue()'), // (3) define 'intArray' (say 'intArray =(int*)calloc(length,sizeof(int))') // (4) fill 'intArray' with random numbers between 0- 'maxRandVal' // (use expression '(rand() % (maxRandVal+1))') // No parameters. No return value. extern void createArray (); // PURPOSE: To print the values in 'intArray[]'. No parameters. No return // value. extern void printArray (); // // Function and variables go here: // // PURPOSE: To hold the minimum value for 'length'. int minArrayLen = 1; // PURPOSE: To hold the maximum value for 'length'. int maxArrayLen = 256; // PURPOSE: To hold the maximum value for 'maxRandVal'. int maxMaxRandVal = 256; // PURPOSE: To hold the length of C-string 'line'.
  • 8. #define MAX_LINE 256 // PURPOSE: To hold the a C-string. char line[MAX_LINE]; // PURPOSE: To have the user enter the variable pointed to by 'valuePtr', // which must be between 'min' and 'max', and which is described by // '*descriptionPtr'. No parameters. No return value. void enterValue (const char* descriptionPtr, int min, int max, int* valuePtr ) { do { printf("Please enter the %s (%d-%d): ",descriptionPtr,min,max); fgets(line,MAX_LINE,stdin); *valuePtr = strtol(line,NULL,10); } while ( (*valuePtr < min) || (*valuePtr > max) ); } // PURPOSE: To free 'intArray'. No parameters. No return value. // void freeArray () {
  • 9. free(intArray); } // PURPOSE: To define the array, print an array, and free the array. No // Ignores parameters. Returns 'EXIT_SUCCESS' to OS. int main () { createArray(); printArray(); freeArray(); return(EXIT_SUCCESS); } Sample output:[[email protected] Assign1]$ gcc -c p1.c [[email protected] Assign1]$ gcc -c p2.c [[email protected] Assign1]$ gcc -o whole p1.o p2.o [[email protected] Assign1]$ ./whole Please enter the array's length (1-256): 0 Please enter the array's length (1-256): 257 Please enter the array's length (1-256): 16 Please enter the maximum random value (1-256): 0 Please enter the maximum random value (1-256): 257 Please enter the maximum random value (1-256): 4 The array is: intArray[0] = 3 intArray[1] = 1 intArray[2] = 2 intArray[3] = 0 intArray[4] = 3 intArray[5] = 0 intArray[6] = 1 intArray[7] = 2 intArray[8] = 4 intArray[9] = 1 intArray[10] = 2
  • 10. intArray[11] = 2 intArray[12] = 0 intArray[13] = 4 intArray[14] = 3 intArray[15] = 1 [[email protected] Assign1]$ (30 Points) Write a program file p2.c that would compile to p2.o, and would link with p1.o to create a legal running program whole. Important: Include your p2.c with your submission! HINTS: What does p1.c need that it does not define?Be sure to extern any necessary functions with the same parameters as they are declared. What does p1.c define that p2.c would need? Be sure to extern both such variable and function symbols. Create the individual object files and the complete executable with: linux> gcc -c p1.c # creates p1.o linux> gcc -c p2.c # creates p2.o linux> gcc p1.o p2.o -o whole # creates whole linux> ./whole # runs whole (5 Points) Use objdump (not gdb!) to disassemble both main() and createArray() in whole. Find the call to createArray() in main(). Show the math of how the number in that call instruction is used to compute the address where createArray() actually is.
  • 11. (5 Points) Which segment (that is: .text, .rodata, .data or .bss) of p1.o has string constant used in enterValue()'s printf() call? Show this with objdump. (5 Points) Can you find the memory for enterValue()'s variable min using objdump? If you can, use objdump to show where it is. If you can't, tell why not. (5 Points) Which segment of p2.o has the function printArray()? Show this with objdump. (5 Points) It is rather inelegant for both p1.c and p2.c to have the code: // PURPOSE: To hold the length of C-string 'line'. #define MAX_LINE 256 because if we decide to make a change we have to remember to change all .c files. Suggest a more elegant solution, one that C encourages.