Skip to content

Commit

Permalink
more answers
Browse files Browse the repository at this point in the history
  • Loading branch information
sayon committed Jul 20, 2017
1 parent f4c361e commit 1896a9f
Show file tree
Hide file tree
Showing 9 changed files with 192 additions and 0 deletions.
18 changes: 18 additions & 0 deletions questions/answers/078.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

# Question 78


What are the compilation stages?


# Answer




Preprocessing, translation, linking




[prev](077.md) +++ [next](079.md)
18 changes: 18 additions & 0 deletions questions/answers/079.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

# Question 79


What is preprocessing?


# Answer



Performing (usually) textual substitution in program source code to
produce a modified source in the same language. The substitutions are
controlled via preprocessor flags (such as `-D`) and preprocessor directives
such as `%define` or `%macro`.


[prev](078.md) +++ [next](080.md)
18 changes: 18 additions & 0 deletions questions/answers/080.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

# Question 80


What is a macro instantiation?


# Answer




When a macro name occurs in program source, it gets substituted with its body.
The macro body with macro parameters substituted is called macro instantiation.



[prev](079.md) +++ [next](081.md)
25 changes: 25 additions & 0 deletions questions/answers/081.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

# Question 81

What is the `%define` directive?


# Answer



`%define` defines a preprocessor substitution.

For example:

```asm
%define hello "Greetings, commander"
db hello, 0 ; gets substituted with: db "Greetings, commander", 0
```

The substitutions occur _before_ code generation.



[prev](080.md) +++ [next](082.md)
34 changes: 34 additions & 0 deletions questions/answers/082.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

# Question 82


What is the `%macro` directive?


# Answer




```macro` directive allows you to define macros whose body spans over multiple
lines.

For example:

```asm
%macro hello 2
dq %1
dq %2
%endmacro
; Instantiation:
hello 42,1337
; substituted for:
; dq 42
; dq 1337
```


[prev](081.md) +++ [next](083.md)
16 changes: 16 additions & 0 deletions questions/answers/086.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

# Question 86


What are the three types of ELF object files?


# Answer



Relocatable object files, shared object files (dynamic libraries) and
executable files.


[prev](085.md) +++ [next](087.md)
17 changes: 17 additions & 0 deletions questions/answers/087.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

# Question 87


What kind of headers are present in an ELF file?


# Answer



* File header (`readelf -f`)
* Program headers (`readelf -h`)
* Section headers (`readelf -S`)


[prev](086.md) +++ [next](088.md)
20 changes: 20 additions & 0 deletions questions/answers/088.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

# Question 88


What is relocation?


# Answer



__Relocation__ is a process of assigning definitive addresses to various program parts
and changing the program code the way all links are attributed correctly. We are
speaking about all kinds of memory accesses by absolute addresses. Relocation is
needed, for example, when the program consists of multiple modules, which are
referencing one another. The order in which they will be placed in memory is not
yet fixed, so the absolute addresses are not determined.


[prev](087.md) +++ [next](089.md)
26 changes: 26 additions & 0 deletions questions/answers/089.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

# Question 89


What sections can be present in ELF files?


# Answer



* __.text__ stores machine instructions.
* __.rodata__ stores read only data.
* __.data__ stores initialized global variables.
* __.bss__ stores readable and writable global variables, initialized to zero. There is no need to dump their contents into an object file as they are all filled with zeros anyway. Instead, a total section size is stored. An operating system may know faster ways of initializing such memory than zeroing it manually. In assembly, you can put data here by placing `resb`, `resw`, and similar directives after the section __.bss__.
* __.rel.text__ stores relocation table for the .text section. It is used to memorize places where a linker should modify .text after choosing the loading address for this specific object file.
* __.rel.data_ stores a relocation table for data referenced in module.
* __.debug__ stores a symbol table used to debug program. If the program was written in C or C++, it will store information not only about global variables (as __.symtab__ does) but also about local variables.
* __.line__ defines correspondence with pieces of code and line numbers in source code. We need it because the correspondence between lines of source code in higher-level languages and assembly instructions is not
straightforward. This information allows one to debug a program in a higher-level language line by line.
* __.strtab__ stores character strings. It is like an array of strings. Other sections, such, as __.symtab__ and __.debug__,
use not immediate strings but their indices in __.strtab__.
* __.symtab__ stores a symbol table. Whenever a programmer defines a label, NASM will create a symbol for it.


[prev](088.md) +++ [next](090.md)

0 comments on commit 1896a9f

Please sign in to comment.