function items and building libraries items

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

what is source code file?

- C++ projects consist of one or more source code files written in the C++ programming language. These files usually have a .cpp extension. - Source code files contain the actual implementation of the program, including functions, classes, and other program logic.

what are libraries and dependencies?

- C++ projects may use external libraries or dependencies to enhance functionality. These dependencies are often specified in the project configuration and are linked during the build process. - Libraries can include precompiled binaries or source code that needs to be compiled along with the project.

Documentation

- Documentation files, such as README files, user guides, or inline comments, provide information about the project's purpose, usage, and implementation details. - Documentation is essential for understanding and maintaining the project.

what is header file?

- Header files (.h or .hpp extensions) are used to declare the interfaces, function prototypes, class declarations, and other information that is shared among multiple source code files. - They are often used to declare reusable code and to separate the interface from the implementation.

Resources

- Resources like images, configuration files, or other assets may be included in the project to support its functionality. - These resources are often managed as part of the project structure.

what does #include pre-compiler directive do?

- The #include preprocessor directive in C++ is used to include the content of another file, typically a header file, into the source code during the preprocessing phase. This directive is part of the C++ preprocessor, which is a tool that performs various transformations on the source code before it is compiled. The primary purpose of #include is to allow code modularization and reuse by incorporating declarations, definitions, or other content from external files into a C++ source file. - This is especially useful for sharing common code across multiple source files or for including libraries and frameworks.

what is function in programming?

- a named piece of code - we can run this piece of code from different places of our program by calling its name - once the function is done, it will move to next instruction after CALL

what is cpp project?

- a project typically includes one or more c++ source files, header files, build configurations, and sometimes additional resources such as images, documentation, or other assets

function calling conventions

- are a set of rules that dictate how functions interact with each other in terms of register usage, argument passing, and stack management. - examples: 1) arguments are passed in "$a0" and "$a3" 2) return values are stored in "$v0" and "$v1" 3) "$ra" should be preserved by callee

what is "building configuration" ?

- build configurations include instructions for compiling and linking the source code into executable file or library. this can involve specifying compiler options, linker settings, and other build-related parameters - build configurations are often managed using build systems or build tools. - they are often provide features such as dependency tracking, incremental builds, and multi-platform support

using the stack and '$sp' for register preservation

- in mips, stack is typically managed using '$sp' (stack pointer) register. - the stack grows downward in memory, and the '$sp' points to the top of the stack. - saving registers: + before modifying any register that needs to be preserved, the current value of that register is usually pushed onto the stack + stack pointer '$sp' is decremented to allocate space for the value on the stack - restoring registers: + restore the original value of a register, the value is popped from the stack + the stack pointer '$sp' is incremented o de-allocate the space on the stack

what is caller? what is callee? can callee also be a caller?

- the caller is the part of the program that invokes (calls) a function - it is responsible for passing arguments to the function and managing the flow of execution - before calling a function, the caller often SAVES the values of registers that it needs to preserve - callee: is the function being called - it is responsible for performing a specific task and returning a result, if necessary - callee often saves values of registers it intends to modify and restores them before returning - when calling a function, use JAL --> jump and link to the function name

what is the input of the pre-compiler?

C++ source code

you must understand that there is just one set of registers that all functions use together

In many processor architectures, including MIPS, there is a set of general-purpose registers that are shared among all functions in a program. These registers include $t0 to $t9 (temporary registers) and $s0 to $s7 (saved registers). - temporary registers: are not preserved across function calls. a calling function can use them freely, but the callee is not required to preserve their values - saved registers: are preserved across function calls. if a callee modifies the values in these registers, it should restore them to their original values before returning

how do we call a function in MIPS?

MIPS functions are called by the JAL function. JAL saves the return address (address of next instruction in the dedicated register $ra)

Does the compiler deal with header files directly?

No, header files become a part of .cpp files after a pre-compiler processes the project

what is the output of compiler?

Object code

main: lw $a0, num1 # Load num1 into register $a0 lw $a1, num2 # Load num2 into register $a1 jal add_numbers # Jump and link to the add_numbers function

in this example, - main is the caller - it loads values into registers $a0 and $a1 and then jumps to "add_number" function using JAL - "add_number" is the callee. it performs the addition, stores result in $v0, and then returns the caller using "jr $ra" - the return address ("$ra") is saved before modifying the stack pointer ($sp), and its restored before returning the caller

example of caller and callee

main: lw $a0, num1 # Load num1 into register $a0 lw $a1, num2 # Load num2 into register $a1 jal add_numbers # Jump and link to the add_numbers function

is there any difference between function label and other labels like the ones we use in loops?

no difference

is there any difference between functions and procedures in our course?

no not in our course

name 3 steps of cpp project building

pre-compilation/pre-processing -> compilation -> linkage

what does pre-compiler deal with?

pre-compiler directives

what does it mean to build a cpp project?

refers to the process of compiling and linking the source code files to generate an executable or library that can b executed or used by other programs. process involves several steps: preprocessing, compilation, linking.

where do we return from the function? in other words, what will be the next instruction executed after the function return?

the next instruction that is executed after the function return will go back to its original place, and call the next instruction on that place

how do we return from function in MIPS?

we return MIPS function by using jr $ra

where do we save value of register?

we save value of register on the stack

how do we name and label a function in MIPS?

we use a label to indicate start of MIPS function


Ensembles d'études connexes

Chapter 1: The Building Blocks of Relationships

View Set

(2) Final Exam: OLT. 24-34 Study Questions (29-34)

View Set

MED TERM 2: CH. 19 MULTIPLE CHOICE

View Set

Test 2 - Chapter 5 - Contraception and Abortion

View Set

movements that occur at synovial joints

View Set

GLG 171 - Chapter 9: Ice, Wind, and Deserts

View Set

Police Studies - Investigation and Report Writing

View Set