From c4015e2d4cb7acbc918e9673c39daf4e136d0f57 Mon Sep 17 00:00:00 2001 From: FrodeM Date: Tue, 26 Aug 2014 15:02:52 +0200 Subject: [PATCH 1/3] Lab 1 Frode Lab 1 fra Frode van der Meeren --- ANSWERS.md | 101 +++++++++++++++++++++++++++++++++-------------------- mysrc.c | 16 +++++++++ 2 files changed, 79 insertions(+), 38 deletions(-) create mode 100644 mysrc.c diff --git a/ANSWERS.md b/ANSWERS.md index 9e5261a..28a5aee 100644 --- a/ANSWERS.md +++ b/ANSWERS.md @@ -19,7 +19,7 @@ Please use [markdown](https://help.github.com/articles/markdown-basics) formatin Make another directory inside the `unixstuff` directory called `backups` -**Answer:** *YOUR ANSWER HERE* +**Answer:** *mkdir unixstuff\backups* ###Exercise 1b @@ -27,25 +27,30 @@ Use the commands `cd`, `ls` and `pwd` to explore the file system. (Remember, if you get lost, type `cd` by itself to return to your home-directory) -**Answer:** *YOUR ANSWER HERE* +**Answer:** *cd unixstuff* ###Exercise 2a Create a backup of your `science.txt` file by copying it to a file called `science.bak` -**Answer:** *YOUR ANSWER HERE* +**Answer:** *cat science.txt>science.bak* ###Exercise 2b Create a directory called `tempstuff` using `mkdir`, then remove it using the `rmdir` command. -**Answer:** *YOUR ANSWER HERE* +**Answer:** *mkdir tempstuff +rmdir -r tempstuff* ###Exercise 3a Using the above method, create another file called `list2` containing the following fruit: orange, plum, mango, grapefruit. Read the contents of `list2`. -**Answer:** *YOUR ANSWER HERE* +**Answer:** *"orange">list2 +"plum">>list2 +"mango">>list2 +"grapefruit">>list2 +cat list2* ###Exercise 3b @@ -64,83 +69,103 @@ Use `ls -l` to check that the permissions have changed. ##Shell questions 1. What option with the command `rm` is required to remove a directory? - - **Answer:** *YOUR ANSWER HERE* + - **Answer:** *rm -r dirname removes directories.* 1. What is the command used to display the manual pages for any command? - - **Answer:** *YOUR ANSWER HERE* + - **Answer:** *man commandname brings up the manual for a command.* 1. What command will show the first 5 lines of an input file? - - **Answer:** *YOUR ANSWER HERE* + - **Answer:** *head -5 filename displays the first 5 lines of a file.* 1. What command can be used to rename a file? - - **Answer:** *YOUR ANSWER HERE* + - **Answer:** *mv filename newfname renames a file.* 1. What option can we given to `ls` to show the hidden files? - - **Answer:** *YOUR ANSWER HERE* + - **Answer:** *ls -a shows the hidden files together with everything else.* 1. What will the command `cat -n file` do? - - **Answer:** *YOUR ANSWER HERE* + - **Answer:** *cat -n filename prints the file, with linenumbers.* 1. What will the command `echo -n hello` do? - - **Answer:** *YOUR ANSWER HERE* + - **Answer:** *echo -n "hello" will print "hello" to standard output, with no new line.* 1. What command will display s list of the users who currently logged in in the system? - - **Answer:** *YOUR ANSWER HERE* + - **Answer:** *who displays all online users.* 1. How do you change password on your account? - - **Answer:** *YOUR ANSWER HERE* + - **Answer:** *passwd is used to change the password.* 1. How can you list a file in reverse order? - - **Answer:** *YOUR ANSWER HERE* + - **Answer:** *cat -n filename>tmp.txt +sort -rn tmp.txt +rm tmp.txt* 1. What does the `less` command do? - - **Answer:** *YOUR ANSWER HERE* + - **Answer:** *less searches for a pattern in a file.* 1. With `less` how do you navigate? - - **Answer:** *YOUR ANSWER HERE* + - **Answer:** *you use /searchword to search and n to go to the next hit.* 1. What command will display the running processes of the current user? - - **Answer:** *YOUR ANSWER HERE* + - **Answer:** *ps displays your processes.* 1. What command can be used to find the process(es) consuming the most CPU? - - **Answer:** *YOUR ANSWER HERE* + - **Answer:** *top displays the processes using most CPU.* ##vi questions 1. How do we save a file in `vi` and continue working? - - **Answer:** *YOUR ANSWER HERE* + - **Answer:** *esc:w [filename] saves the file without quitting.* 1. What command/key is used to start entering text? - - **Answer:** *YOUR ANSWER HERE* + - **Answer:** *the i key can be used to enter text.* 1. What are the different modes the editor can be in? - - **Answer:** *YOUR ANSWER HERE* + - **Answer:** *command mode and insert mode.* 1. What command can be used to place the cursor at the beginning of line 4? - - **Answer:** *YOUR ANSWER HERE* + - **Answer:** *:4 will take the cursor to line 4* 1. What will `dd` command do (in command-mode)? - - **Answer:** *YOUR ANSWER HERE* + - **Answer:** *dd will erease the curent line.* 1. How do you undo the most recent changes? - - **Answer:** *YOUR ANSWER HERE* + - **Answer:** *u or :u undo the most recent changes* 1. How do you move back one word? - - **Answer:** *YOUR ANSWER HERE* + - **Answer:** *b moves back one word.* ##The C Language and Make tool Questions 1. How do you use `gcc` to only produce the `.o` file? What is the difference between generating only the `.o` file, and building the `hello` executable done in the previous compilation above? - - **Answer:** *YOUR ANSWER HERE* + - **Answer:** *gcc -c hello.c will generate compiled but unlinked object files from the sources, whereas a full compile will link everything together in an excecutable file.* 1. Give the command for compiling with `debug` enabled instead of normal compilation for the two examples shown in Listing 2 and Listing 3. Explain how to turn debugging on/off for the two cases. - - **Answer:** *YOUR ANSWER HERE* + - **Answer:** *gcc -g hello.c compiles with debug mode enabled in the compiler. For the two programs, however, Listing 2 needs to have the DEBUG tag defined, while Listing 3 needs to have the debug variable set to something else than zero.* 1. Give a brief pros and cons discussion for the two methods to add debug code shown in Listing 2 and Listing 3. - - **Answer:** *YOUR ANSWER HERE* + - **Answer:** *For Listing 2, debug code is left out already during compilation and will not be present unless compiled with debug enabled. For Listing 3, debug code will be included in the program code after compilation, but it will not be excecuted unless the flag is specified. The method of Listing 2 is great for saving space, but the method of Listing 3 allows for code that's easier to read along with more flexible debug intergration.* 1. Provide the command for generating the *map* file. Which of the `gcc` tools is responsible for producing a *map* file? - - **Answer:** *YOUR ANSWER HERE* + - **Answer:** *gcc -o hello -Wl,-Map=hello.map hello.c, the linker makes this file.* 1. What is the content of each of the sections in a *map* file. Explain briefly. - - **Answer:** *YOUR ANSWER HERE* + - **Answer:** *The map file defines where libraries, variables and code will be allocated in memory. You have the stack for stack based functions, dataareas for constants and variables, and code area for code.* 1. Rewrite `hello.c` to produce entries in the *map* file for `.data`, `.bss`, and `.rodata`. Hint: This can be done by adding one variable for each type to the file. - - **Answer:** *YOUR ANSWER HERE* + - **Answer:** *tried adding variables, but program wouldn't recognize the globally defined string* 1. Add the following function to `hello.c`: `double multiply(double x1, double x2)`, which returns `x1*x2`. Use `gcc` to generate an assembly code listing for the program, and examine the assembly code. What assembly instructions are used to do this? Repeat this task, but now replace `double` with `float`. Explain! - - **Answer:** *YOUR ANSWER HERE* + - **Answer:** *The x86 instruction set has instructions for integer multiplication, but not for floating point multiplication (unless a numeric x87 coproccessor is used. Since the 486DX these coprocessors have been intergrated in the main CPU)* 1. How does `make` know if a file must be recompiled? - - **Answer:** *YOUR ANSWER HERE* + - **Answer:** *it's predefined. Libraries does not need to be recompiled.* 1. Provide a `make` command to use a file named `mymakefile` instead of the default `makefile`. - - **Answer:** *YOUR ANSWER HERE* + - **Answer:** *make -f mymakefile* 1. How do you implement an *include guard*, and why is it needed? - - **Answer:** *YOUR ANSWER HERE* + - **Answer:** *To prevent several inclusions of a library. This saves space and prevents linking conflicts.* ##Library Task Insert your code between the brackets `{}`: - void main( int argc, char *argv[] ) + void main( int argc, char *argv[] ) { - } + argv = char[argc]; + for(int i=0; i + +char[] alph = "Hello, world!\n\0"; + +int main(void) +{ + double a = 5; + double b = 7; + double c = a*b; + float a2 = 5.0; + float b2 = 7.0; + float c2 = a2*b2; + int n = 0; + printf(alph); + return n; +} From 156ed61a6638d4310d04fb15f33ecbe073e92d70 Mon Sep 17 00:00:00 2001 From: FrodeM Date: Tue, 26 Aug 2014 15:06:04 +0200 Subject: [PATCH 2/3] Revert "Lab 1 Frode" This reverts commit c4015e2d4cb7acbc918e9673c39daf4e136d0f57. --- ANSWERS.md | 101 ++++++++++++++++++++--------------------------------- mysrc.c | 16 --------- 2 files changed, 38 insertions(+), 79 deletions(-) delete mode 100644 mysrc.c diff --git a/ANSWERS.md b/ANSWERS.md index 28a5aee..9e5261a 100644 --- a/ANSWERS.md +++ b/ANSWERS.md @@ -19,7 +19,7 @@ Please use [markdown](https://help.github.com/articles/markdown-basics) formatin Make another directory inside the `unixstuff` directory called `backups` -**Answer:** *mkdir unixstuff\backups* +**Answer:** *YOUR ANSWER HERE* ###Exercise 1b @@ -27,30 +27,25 @@ Use the commands `cd`, `ls` and `pwd` to explore the file system. (Remember, if you get lost, type `cd` by itself to return to your home-directory) -**Answer:** *cd unixstuff* +**Answer:** *YOUR ANSWER HERE* ###Exercise 2a Create a backup of your `science.txt` file by copying it to a file called `science.bak` -**Answer:** *cat science.txt>science.bak* +**Answer:** *YOUR ANSWER HERE* ###Exercise 2b Create a directory called `tempstuff` using `mkdir`, then remove it using the `rmdir` command. -**Answer:** *mkdir tempstuff -rmdir -r tempstuff* +**Answer:** *YOUR ANSWER HERE* ###Exercise 3a Using the above method, create another file called `list2` containing the following fruit: orange, plum, mango, grapefruit. Read the contents of `list2`. -**Answer:** *"orange">list2 -"plum">>list2 -"mango">>list2 -"grapefruit">>list2 -cat list2* +**Answer:** *YOUR ANSWER HERE* ###Exercise 3b @@ -69,103 +64,83 @@ Use `ls -l` to check that the permissions have changed. ##Shell questions 1. What option with the command `rm` is required to remove a directory? - - **Answer:** *rm -r dirname removes directories.* + - **Answer:** *YOUR ANSWER HERE* 1. What is the command used to display the manual pages for any command? - - **Answer:** *man commandname brings up the manual for a command.* + - **Answer:** *YOUR ANSWER HERE* 1. What command will show the first 5 lines of an input file? - - **Answer:** *head -5 filename displays the first 5 lines of a file.* + - **Answer:** *YOUR ANSWER HERE* 1. What command can be used to rename a file? - - **Answer:** *mv filename newfname renames a file.* + - **Answer:** *YOUR ANSWER HERE* 1. What option can we given to `ls` to show the hidden files? - - **Answer:** *ls -a shows the hidden files together with everything else.* + - **Answer:** *YOUR ANSWER HERE* 1. What will the command `cat -n file` do? - - **Answer:** *cat -n filename prints the file, with linenumbers.* + - **Answer:** *YOUR ANSWER HERE* 1. What will the command `echo -n hello` do? - - **Answer:** *echo -n "hello" will print "hello" to standard output, with no new line.* + - **Answer:** *YOUR ANSWER HERE* 1. What command will display s list of the users who currently logged in in the system? - - **Answer:** *who displays all online users.* + - **Answer:** *YOUR ANSWER HERE* 1. How do you change password on your account? - - **Answer:** *passwd is used to change the password.* + - **Answer:** *YOUR ANSWER HERE* 1. How can you list a file in reverse order? - - **Answer:** *cat -n filename>tmp.txt -sort -rn tmp.txt -rm tmp.txt* + - **Answer:** *YOUR ANSWER HERE* 1. What does the `less` command do? - - **Answer:** *less searches for a pattern in a file.* + - **Answer:** *YOUR ANSWER HERE* 1. With `less` how do you navigate? - - **Answer:** *you use /searchword to search and n to go to the next hit.* + - **Answer:** *YOUR ANSWER HERE* 1. What command will display the running processes of the current user? - - **Answer:** *ps displays your processes.* + - **Answer:** *YOUR ANSWER HERE* 1. What command can be used to find the process(es) consuming the most CPU? - - **Answer:** *top displays the processes using most CPU.* + - **Answer:** *YOUR ANSWER HERE* ##vi questions 1. How do we save a file in `vi` and continue working? - - **Answer:** *esc:w [filename] saves the file without quitting.* + - **Answer:** *YOUR ANSWER HERE* 1. What command/key is used to start entering text? - - **Answer:** *the i key can be used to enter text.* + - **Answer:** *YOUR ANSWER HERE* 1. What are the different modes the editor can be in? - - **Answer:** *command mode and insert mode.* + - **Answer:** *YOUR ANSWER HERE* 1. What command can be used to place the cursor at the beginning of line 4? - - **Answer:** *:4 will take the cursor to line 4* + - **Answer:** *YOUR ANSWER HERE* 1. What will `dd` command do (in command-mode)? - - **Answer:** *dd will erease the curent line.* + - **Answer:** *YOUR ANSWER HERE* 1. How do you undo the most recent changes? - - **Answer:** *u or :u undo the most recent changes* + - **Answer:** *YOUR ANSWER HERE* 1. How do you move back one word? - - **Answer:** *b moves back one word.* + - **Answer:** *YOUR ANSWER HERE* ##The C Language and Make tool Questions 1. How do you use `gcc` to only produce the `.o` file? What is the difference between generating only the `.o` file, and building the `hello` executable done in the previous compilation above? - - **Answer:** *gcc -c hello.c will generate compiled but unlinked object files from the sources, whereas a full compile will link everything together in an excecutable file.* + - **Answer:** *YOUR ANSWER HERE* 1. Give the command for compiling with `debug` enabled instead of normal compilation for the two examples shown in Listing 2 and Listing 3. Explain how to turn debugging on/off for the two cases. - - **Answer:** *gcc -g hello.c compiles with debug mode enabled in the compiler. For the two programs, however, Listing 2 needs to have the DEBUG tag defined, while Listing 3 needs to have the debug variable set to something else than zero.* + - **Answer:** *YOUR ANSWER HERE* 1. Give a brief pros and cons discussion for the two methods to add debug code shown in Listing 2 and Listing 3. - - **Answer:** *For Listing 2, debug code is left out already during compilation and will not be present unless compiled with debug enabled. For Listing 3, debug code will be included in the program code after compilation, but it will not be excecuted unless the flag is specified. The method of Listing 2 is great for saving space, but the method of Listing 3 allows for code that's easier to read along with more flexible debug intergration.* + - **Answer:** *YOUR ANSWER HERE* 1. Provide the command for generating the *map* file. Which of the `gcc` tools is responsible for producing a *map* file? - - **Answer:** *gcc -o hello -Wl,-Map=hello.map hello.c, the linker makes this file.* + - **Answer:** *YOUR ANSWER HERE* 1. What is the content of each of the sections in a *map* file. Explain briefly. - - **Answer:** *The map file defines where libraries, variables and code will be allocated in memory. You have the stack for stack based functions, dataareas for constants and variables, and code area for code.* + - **Answer:** *YOUR ANSWER HERE* 1. Rewrite `hello.c` to produce entries in the *map* file for `.data`, `.bss`, and `.rodata`. Hint: This can be done by adding one variable for each type to the file. - - **Answer:** *tried adding variables, but program wouldn't recognize the globally defined string* + - **Answer:** *YOUR ANSWER HERE* 1. Add the following function to `hello.c`: `double multiply(double x1, double x2)`, which returns `x1*x2`. Use `gcc` to generate an assembly code listing for the program, and examine the assembly code. What assembly instructions are used to do this? Repeat this task, but now replace `double` with `float`. Explain! - - **Answer:** *The x86 instruction set has instructions for integer multiplication, but not for floating point multiplication (unless a numeric x87 coproccessor is used. Since the 486DX these coprocessors have been intergrated in the main CPU)* + - **Answer:** *YOUR ANSWER HERE* 1. How does `make` know if a file must be recompiled? - - **Answer:** *it's predefined. Libraries does not need to be recompiled.* + - **Answer:** *YOUR ANSWER HERE* 1. Provide a `make` command to use a file named `mymakefile` instead of the default `makefile`. - - **Answer:** *make -f mymakefile* + - **Answer:** *YOUR ANSWER HERE* 1. How do you implement an *include guard*, and why is it needed? - - **Answer:** *To prevent several inclusions of a library. This saves space and prevents linking conflicts.* + - **Answer:** *YOUR ANSWER HERE* ##Library Task Insert your code between the brackets `{}`: - void main( int argc, char *argv[] ) + void main( int argc, char *argv[] ) { - argv = char[argc]; - for(int i=0; i - -char[] alph = "Hello, world!\n\0"; - -int main(void) -{ - double a = 5; - double b = 7; - double c = a*b; - float a2 = 5.0; - float b2 = 7.0; - float c2 = a2*b2; - int n = 0; - printf(alph); - return n; -} From 7dc54886f757f1887e0652e82a6977ef56372ccb Mon Sep 17 00:00:00 2001 From: FrodeM Date: Thu, 4 Sep 2014 12:21:04 +0200 Subject: [PATCH 3/3] Revert "Revert "Lab 1 Frode"" This reverts commit 156ed61a6638d4310d04fb15f33ecbe073e92d70. --- ANSWERS.md | 101 +++++++++++++++++++++++++++++++++-------------------- mysrc.c | 16 +++++++++ 2 files changed, 79 insertions(+), 38 deletions(-) create mode 100644 mysrc.c diff --git a/ANSWERS.md b/ANSWERS.md index 9e5261a..28a5aee 100644 --- a/ANSWERS.md +++ b/ANSWERS.md @@ -19,7 +19,7 @@ Please use [markdown](https://help.github.com/articles/markdown-basics) formatin Make another directory inside the `unixstuff` directory called `backups` -**Answer:** *YOUR ANSWER HERE* +**Answer:** *mkdir unixstuff\backups* ###Exercise 1b @@ -27,25 +27,30 @@ Use the commands `cd`, `ls` and `pwd` to explore the file system. (Remember, if you get lost, type `cd` by itself to return to your home-directory) -**Answer:** *YOUR ANSWER HERE* +**Answer:** *cd unixstuff* ###Exercise 2a Create a backup of your `science.txt` file by copying it to a file called `science.bak` -**Answer:** *YOUR ANSWER HERE* +**Answer:** *cat science.txt>science.bak* ###Exercise 2b Create a directory called `tempstuff` using `mkdir`, then remove it using the `rmdir` command. -**Answer:** *YOUR ANSWER HERE* +**Answer:** *mkdir tempstuff +rmdir -r tempstuff* ###Exercise 3a Using the above method, create another file called `list2` containing the following fruit: orange, plum, mango, grapefruit. Read the contents of `list2`. -**Answer:** *YOUR ANSWER HERE* +**Answer:** *"orange">list2 +"plum">>list2 +"mango">>list2 +"grapefruit">>list2 +cat list2* ###Exercise 3b @@ -64,83 +69,103 @@ Use `ls -l` to check that the permissions have changed. ##Shell questions 1. What option with the command `rm` is required to remove a directory? - - **Answer:** *YOUR ANSWER HERE* + - **Answer:** *rm -r dirname removes directories.* 1. What is the command used to display the manual pages for any command? - - **Answer:** *YOUR ANSWER HERE* + - **Answer:** *man commandname brings up the manual for a command.* 1. What command will show the first 5 lines of an input file? - - **Answer:** *YOUR ANSWER HERE* + - **Answer:** *head -5 filename displays the first 5 lines of a file.* 1. What command can be used to rename a file? - - **Answer:** *YOUR ANSWER HERE* + - **Answer:** *mv filename newfname renames a file.* 1. What option can we given to `ls` to show the hidden files? - - **Answer:** *YOUR ANSWER HERE* + - **Answer:** *ls -a shows the hidden files together with everything else.* 1. What will the command `cat -n file` do? - - **Answer:** *YOUR ANSWER HERE* + - **Answer:** *cat -n filename prints the file, with linenumbers.* 1. What will the command `echo -n hello` do? - - **Answer:** *YOUR ANSWER HERE* + - **Answer:** *echo -n "hello" will print "hello" to standard output, with no new line.* 1. What command will display s list of the users who currently logged in in the system? - - **Answer:** *YOUR ANSWER HERE* + - **Answer:** *who displays all online users.* 1. How do you change password on your account? - - **Answer:** *YOUR ANSWER HERE* + - **Answer:** *passwd is used to change the password.* 1. How can you list a file in reverse order? - - **Answer:** *YOUR ANSWER HERE* + - **Answer:** *cat -n filename>tmp.txt +sort -rn tmp.txt +rm tmp.txt* 1. What does the `less` command do? - - **Answer:** *YOUR ANSWER HERE* + - **Answer:** *less searches for a pattern in a file.* 1. With `less` how do you navigate? - - **Answer:** *YOUR ANSWER HERE* + - **Answer:** *you use /searchword to search and n to go to the next hit.* 1. What command will display the running processes of the current user? - - **Answer:** *YOUR ANSWER HERE* + - **Answer:** *ps displays your processes.* 1. What command can be used to find the process(es) consuming the most CPU? - - **Answer:** *YOUR ANSWER HERE* + - **Answer:** *top displays the processes using most CPU.* ##vi questions 1. How do we save a file in `vi` and continue working? - - **Answer:** *YOUR ANSWER HERE* + - **Answer:** *esc:w [filename] saves the file without quitting.* 1. What command/key is used to start entering text? - - **Answer:** *YOUR ANSWER HERE* + - **Answer:** *the i key can be used to enter text.* 1. What are the different modes the editor can be in? - - **Answer:** *YOUR ANSWER HERE* + - **Answer:** *command mode and insert mode.* 1. What command can be used to place the cursor at the beginning of line 4? - - **Answer:** *YOUR ANSWER HERE* + - **Answer:** *:4 will take the cursor to line 4* 1. What will `dd` command do (in command-mode)? - - **Answer:** *YOUR ANSWER HERE* + - **Answer:** *dd will erease the curent line.* 1. How do you undo the most recent changes? - - **Answer:** *YOUR ANSWER HERE* + - **Answer:** *u or :u undo the most recent changes* 1. How do you move back one word? - - **Answer:** *YOUR ANSWER HERE* + - **Answer:** *b moves back one word.* ##The C Language and Make tool Questions 1. How do you use `gcc` to only produce the `.o` file? What is the difference between generating only the `.o` file, and building the `hello` executable done in the previous compilation above? - - **Answer:** *YOUR ANSWER HERE* + - **Answer:** *gcc -c hello.c will generate compiled but unlinked object files from the sources, whereas a full compile will link everything together in an excecutable file.* 1. Give the command for compiling with `debug` enabled instead of normal compilation for the two examples shown in Listing 2 and Listing 3. Explain how to turn debugging on/off for the two cases. - - **Answer:** *YOUR ANSWER HERE* + - **Answer:** *gcc -g hello.c compiles with debug mode enabled in the compiler. For the two programs, however, Listing 2 needs to have the DEBUG tag defined, while Listing 3 needs to have the debug variable set to something else than zero.* 1. Give a brief pros and cons discussion for the two methods to add debug code shown in Listing 2 and Listing 3. - - **Answer:** *YOUR ANSWER HERE* + - **Answer:** *For Listing 2, debug code is left out already during compilation and will not be present unless compiled with debug enabled. For Listing 3, debug code will be included in the program code after compilation, but it will not be excecuted unless the flag is specified. The method of Listing 2 is great for saving space, but the method of Listing 3 allows for code that's easier to read along with more flexible debug intergration.* 1. Provide the command for generating the *map* file. Which of the `gcc` tools is responsible for producing a *map* file? - - **Answer:** *YOUR ANSWER HERE* + - **Answer:** *gcc -o hello -Wl,-Map=hello.map hello.c, the linker makes this file.* 1. What is the content of each of the sections in a *map* file. Explain briefly. - - **Answer:** *YOUR ANSWER HERE* + - **Answer:** *The map file defines where libraries, variables and code will be allocated in memory. You have the stack for stack based functions, dataareas for constants and variables, and code area for code.* 1. Rewrite `hello.c` to produce entries in the *map* file for `.data`, `.bss`, and `.rodata`. Hint: This can be done by adding one variable for each type to the file. - - **Answer:** *YOUR ANSWER HERE* + - **Answer:** *tried adding variables, but program wouldn't recognize the globally defined string* 1. Add the following function to `hello.c`: `double multiply(double x1, double x2)`, which returns `x1*x2`. Use `gcc` to generate an assembly code listing for the program, and examine the assembly code. What assembly instructions are used to do this? Repeat this task, but now replace `double` with `float`. Explain! - - **Answer:** *YOUR ANSWER HERE* + - **Answer:** *The x86 instruction set has instructions for integer multiplication, but not for floating point multiplication (unless a numeric x87 coproccessor is used. Since the 486DX these coprocessors have been intergrated in the main CPU)* 1. How does `make` know if a file must be recompiled? - - **Answer:** *YOUR ANSWER HERE* + - **Answer:** *it's predefined. Libraries does not need to be recompiled.* 1. Provide a `make` command to use a file named `mymakefile` instead of the default `makefile`. - - **Answer:** *YOUR ANSWER HERE* + - **Answer:** *make -f mymakefile* 1. How do you implement an *include guard*, and why is it needed? - - **Answer:** *YOUR ANSWER HERE* + - **Answer:** *To prevent several inclusions of a library. This saves space and prevents linking conflicts.* ##Library Task Insert your code between the brackets `{}`: - void main( int argc, char *argv[] ) + void main( int argc, char *argv[] ) { - } + argv = char[argc]; + for(int i=0; i + +char[] alph = "Hello, world!\n\0"; + +int main(void) +{ + double a = 5; + double b = 7; + double c = a*b; + float a2 = 5.0; + float b2 = 7.0; + float c2 = a2*b2; + int n = 0; + printf(alph); + return n; +}