C & Compilation Flashcards

1
Q

What are the common languages of choice for low level programming

A

+ C due to the amount of control given to the programmer
+ Python because its easier for a programmer to understand and write code quickly
+ Rust because safety go burrr

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What do *.h files contain

A

The declarations for functions and variables which a given c file exposes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What number can be special in some scenarios in c, what are some of these scenarios

A

0:
+ Any value which is not 0 is true
+ \0 is used to mark the end of strings
+ A pointer to address 0 is NULL and invalid

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

When is cross compilation used

A

When compilation on the target device is impossible or impracticable, for example:
+ For the first compiler on new hardware or a new OS
+ For low capability targets such as the Pico’s

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the 4 stages of the compiler driver (to produce an object or ELF file from a C file)

A

Preprocessor
Compiler
Assembler
Linker

For cross-compilation we use:
Cross-Compiler
Cross-Assembler
Cross-Linker

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the job of the preprocess, what files does it consider

A

The preprocessor takes *.c files, expands macros and replaces include directives with the code blocks they reference. This produces a .i file

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the job of the compiler in the compile driver process

A

The compiler takes preprocessed code, parses it and optimises it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

To what form does the compiler (as a step) parse the code it is given

A

The compiler parses code to an “Intermediate Representation”, this is a strongly typed, assembly like, RISC instruction set which is abstract from details of source code and the target machine

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does the compiler (as a step) do once it has parsed code to an Intermediate Representation (IR)

A

It parses it to an optimiser such as the LLVM optimiser which apply’s a set of known optimisations (such as reversing the direction of for loops) to it

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Why is it useful to parse C code to an Intermediate Representation before optimising it

A

Because it allows the same optimiser to be used for multiple languages

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What does the assembler convert its input to

A

The assembler takes the intermediate representation of the program and converts it to a relocatable file such as .o. or .elf

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the 4 most important sections of a relocatable file (i.e. *.o or *.elf)

A

.text
.rodata
.data
.bss

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What does the .text section of a relocatable file contain, and where is this placed when the file is loaded

A

.text contains instructions and gets placed into flash memory when the program is loaded

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What does the .rodata section of a relocatable file contain and where is this placed when the file is loaded

A

.rodata contains read only data and is placed into flash memory when the program is loaded

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What does the .data section of a relocatable file conatain and where is this placed when the file is loaded

A

.data contains Initialised global variables which are placed into flash to be copied into RAM when the program is loaded

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the job of the linker

A

The linker takes Relocatable files and combines them to produce new Relocatable Files, merging the sections of the files

17
Q

What does the linker bottleneck refer to

A

The inker bottleneck refers to the fact compilation can be done in parallel, while linking cannot and MUST be done sequentially

18
Q

What operation does a loader perform

A

A loader accepts a relocatable file and places the sections into physical memory

19
Q

When a c program is loaded into memory, where are global and static variables placed (for one example memory location

A

Global and static variables are placed after the text segment and before the heap

They are split up into those which are initialized and those which are not

20
Q

What is the heap used for

A

The heap is the segment in memory which can be dynamically allocated, this can be accessed with commands such as malloc, realloc and free

21
Q

What is the stack used for

A

The stack is used to store stack frames, these are created whenever a function is called and removed when the function is left, they contain local variables

22
Q

How could the amount of memory available to a program be estimated

A

By creating a new item on the stack (new local var) s, and a new item on the heap (i.e. with malloc) h and taking s* - h*

23
Q
A