Starting from:
$30

$24

Lab 1 Solution




You answers will be in the form of a PDF/C Code. You will submit a zip file named your last name first letter of your first name lab1.zip. (Example steinerslab1.zip)




NOTE 1: For this lab the answers for problem 1 through problem 4 will be placed in a single PDF file named lab1answers.pdf. You must label the problem and the question then your answer. Failure to do so will result in 0 points per problem.










Provided is a C file named cscd340_s18_lab1prob2.c Within the C file are printf statements. Use the starting address for a, b, c, and i starting addresses below.



For each printf statement explain what you believe will be displayed. I want an educated guess. Your output for this will be similar to the following:




Your output for this will be similar to the following:




a = 0022FF00, b = 0022FEFC, c = 0022FEF8, i = 0022FEF4



b = 002D0F98, c = FFFFFFFE



Save these guess as a question #1 in your PDF.







After you have made an educated guess for question 2, compile and execute the code. Copy your output and either verify you were correct or explain where you went wrong. Your output for this will be similar to the following:



Given the starting addresses of:




a = 0x7fffd191bc10, b = 0x7fffd191bc08, c = 0x7fffd191bc00, i = 0x7fffd191bbfc My program produced: a=0x7fffd0517680 b=0x????????




Although the addresses are different I was correct in how many bytes were allocated between a, b, c and i.




NOTE: For #6 just give me your best guess and why you think that value is correct.

It is important that you have a fundamental understanding of pointers and pointer arithmetic, especially the differences between the HEAP and the stack. To illustrate that understanding answer the following



Does the stack grow up or down? How do you know? Justify your answer.
What version of GCC are you using?



What is odd about how memory is arranged compared to the declarations, especially the declara-tions in main?



Does the array declaration, in main, leak memory? Why are why not? (Here I am looking for where array resides in memory)



Does the calloc, in main, leak memory? Why are why not? (Here I am looking for where the varia-ble resides in memory) If yes how many bytes?



Does the malloc, in foo, leak memory? Why are why not? (Here I am looking for where the varia-ble resides in memory) If yes how many bytes?



Does the calloc, in foo, leak memory? Why are why not? (Here I am looking for where the varia-ble resides in memory) If yes how many bytes?



Run the program twice and each time construct a memory map.
Did the addresses change between runs? Why or why not? Justify your answer.
Provide the valgrind in the PDF.






Provided is a C file named cscd340_s18_lab1prob4.c



Within the C file are 9 variable declarations your task is to identify where those variables are located within the process image. The valid location values are: data segment global, data segment local, BSS global, BSS local, heap local, and stack local. Take the code from prob 4 and make your guess.



Using either readelf or objdump verify your answers are correct. If you don’t know how to use either execute the command readelf or objdump –help



If you were incorrect state so and what the correct location is.




NOTE: It is important that you have a fundamental understanding of the process image, and where items are located, especially the differences between the HEAP and the stack.

Provided is a C file named cscd340_s18_lab1prob5.c



I have provided genericArray.h. I have also provided an API specification. To see the methods, you need to write open doc/index.html. In short you need to write:



genericArray.c – Write the methods specified in genericArray.h



myInt.h and myInt.c – Write the structure, the method headers and the method bodies as specified in the API.



myWord.h and myWord.c - Write the structure, the method headers and the method bodies as specified in the API.



I provided a Makefile to compile your code – simply type make



NOTE: You can’t modify the main










TO TURN IN




zip



Your PDF file All C files

My Makefile




A valgrind run for problem 5 - named cscd340_s18_lab1prob5val.txt - showing you are leak free. A sample run of problem 5 illustrating everything works – named cscd340_s18_lab1prob5out.txt




Name your zip – your last name first letter of your first name lab1.zip (Example: steinerslab1.zip)




Please keep all the naming lowercase

More products