From c5e48575b12b5a8d3056b1a8185456f7da153f64 Mon Sep 17 00:00:00 2001 From: sayon Date: Thu, 20 Jul 2017 23:41:13 +0200 Subject: [PATCH] more answers --- questions/answers/005.md | 8 ++++---- questions/answers/007.md | 2 +- questions/answers/089.md | 2 +- questions/answers/090.md | 19 +++++++++++++++++++ questions/answers/091.md | 21 +++++++++++++++++++++ questions/answers/092.md | 16 ++++++++++++++++ questions/answers/093.md | 18 ++++++++++++++++++ questions/answers/094.md | 22 ++++++++++++++++++++++ questions/answers/095.md | 16 ++++++++++++++++ questions/answers/097.md | 19 +++++++++++++++++++ questions/answers/098.md | 29 +++++++++++++++++++++++++++++ questions/answers/099.md | 17 +++++++++++++++++ questions/answers/100.md | 16 ++++++++++++++++ questions/answers/102.md | 17 +++++++++++++++++ questions/answers/103.md | 19 +++++++++++++++++++ questions/answers/104.md | 15 +++++++++++++++ questions/answers/105.md | 16 ++++++++++++++++ questions/answers/107.md | 15 +++++++++++++++ questions/answers/108.md | 20 ++++++++++++++++++++ questions/answers/109.md | 16 ++++++++++++++++ questions/answers/110.md | 15 +++++++++++++++ questions/answers/111.md | 21 +++++++++++++++++++++ questions/answers/112.md | 20 ++++++++++++++++++++ questions/answers/113.md | 16 ++++++++++++++++ questions/answers/120.md | 18 ++++++++++++++++++ questions/answers/122.md | 19 +++++++++++++++++++ questions/answers/123.md | 18 ++++++++++++++++++ questions/answers/124.md | 15 +++++++++++++++ questions/answers/125.md | 25 +++++++++++++++++++++++++ questions/answers/126.md | 34 ++++++++++++++++++++++++++++++++++ questions/answers/127.md | 16 ++++++++++++++++ questions/answers/128.md | 28 ++++++++++++++++++++++++++++ questions/answers/129.md | 16 ++++++++++++++++ questions/answers/130.md | 15 +++++++++++++++ questions/answers/134.md | 17 +++++++++++++++++ questions/answers/135.md | 14 ++++++++++++++ questions/answers/136.md | 16 ++++++++++++++++ questions/answers/137.md | 16 ++++++++++++++++ questions/answers/140.md | 17 +++++++++++++++++ questions/answers/141.md | 16 ++++++++++++++++ questions/answers/142.md | 15 +++++++++++++++ questions/answers/143.md | 19 +++++++++++++++++++ 42 files changed, 723 insertions(+), 6 deletions(-) create mode 100644 questions/answers/090.md create mode 100644 questions/answers/091.md create mode 100644 questions/answers/092.md create mode 100644 questions/answers/093.md create mode 100644 questions/answers/094.md create mode 100644 questions/answers/095.md create mode 100644 questions/answers/097.md create mode 100644 questions/answers/098.md create mode 100644 questions/answers/099.md create mode 100644 questions/answers/100.md create mode 100644 questions/answers/102.md create mode 100644 questions/answers/103.md create mode 100644 questions/answers/104.md create mode 100644 questions/answers/105.md create mode 100644 questions/answers/107.md create mode 100644 questions/answers/108.md create mode 100644 questions/answers/109.md create mode 100644 questions/answers/110.md create mode 100644 questions/answers/111.md create mode 100644 questions/answers/112.md create mode 100644 questions/answers/113.md create mode 100644 questions/answers/120.md create mode 100644 questions/answers/122.md create mode 100644 questions/answers/123.md create mode 100644 questions/answers/124.md create mode 100644 questions/answers/125.md create mode 100644 questions/answers/126.md create mode 100644 questions/answers/127.md create mode 100644 questions/answers/128.md create mode 100644 questions/answers/129.md create mode 100644 questions/answers/130.md create mode 100644 questions/answers/134.md create mode 100644 questions/answers/135.md create mode 100644 questions/answers/136.md create mode 100644 questions/answers/137.md create mode 100644 questions/answers/140.md create mode 100644 questions/answers/141.md create mode 100644 questions/answers/142.md create mode 100644 questions/answers/143.md diff --git a/questions/answers/005.md b/questions/answers/005.md index df3cbb1..a01251a 100644 --- a/questions/answers/005.md +++ b/questions/answers/005.md @@ -17,11 +17,11 @@ the program itself. After a signal (external or internal) is caught, a program’s execution is suspended, some registers are saved, and the CPU starts executing a special routine to handle the situation. Following are exemplary situations when an interrupt occurs (and an appropriate piece of code is executed to handle it): -• A signal from an external device (external interrupt). -• Zero division (internal interrupt). -• Invalid instruction (when CPU failed to recognize an instruction by its binary +* A signal from an external device (external interrupt). +* Zero division (internal interrupt). +* Invalid instruction (when CPU failed to recognize an instruction by its binary representation -- internal interrupt). -• An attempt to execute a privileged instruction in a non-privileged mode (internal interrupt). +* An attempt to execute a privileged instruction in a non-privileged mode (internal interrupt). diff --git a/questions/answers/007.md b/questions/answers/007.md index 3ef9e04..dc37f7f 100644 --- a/questions/answers/007.md +++ b/questions/answers/007.md @@ -2,7 +2,7 @@ # Question 7 -What are the main general purpose registers of \arch? +What are the main general purpose registers of Intel 64? # Answer diff --git a/questions/answers/089.md b/questions/answers/089.md index 9a0be83..19d9268 100644 --- a/questions/answers/089.md +++ b/questions/answers/089.md @@ -14,7 +14,7 @@ What sections can be present in ELF files? * __.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. +* __.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. diff --git a/questions/answers/090.md b/questions/answers/090.md new file mode 100644 index 0000000..eff0d7c --- /dev/null +++ b/questions/answers/090.md @@ -0,0 +1,19 @@ + +# Question 90 + + +What is a symbol table? What kind of information does it store? + + +# Answer + + + +In ELF files, this table stores information about all object symbols. An object +symbol usually corresponds to a label in assembly file. Linker can use it to +e.g. link the usage of a global variable, declared in one file, to its absolute +address. This address is only known after relocation, so it is the linker's +responsibility to fill it. + + +[prev](089.md) +++ [next](091.md) diff --git a/questions/answers/091.md b/questions/answers/091.md new file mode 100644 index 0000000..1e9c5d8 --- /dev/null +++ b/questions/answers/091.md @@ -0,0 +1,21 @@ + +# Question 91 + + +Is there a connection between sections and segments? + + +# Answer + + + +* Section is a static phenomenon, whereas segments are created in runtime. +* Sections are declared in section header, segments are declared in program headers. +* Each segment is a container for one or several sections. +* Not all sections are put into segments (and are loaded at all -- e.g., __line__). +* Segments define permissions for the virtual pages they consist of. If multiple +data sections are put inside one segment, they will all be e.g. non-executable. + + + +[prev](090.md) +++ [next](092.md) diff --git a/questions/answers/092.md b/questions/answers/092.md new file mode 100644 index 0000000..3e2fe03 --- /dev/null +++ b/questions/answers/092.md @@ -0,0 +1,16 @@ + +# Question 92 + + +Is there a connection between assembly sections and ELF sections? + + +# Answer + + + +Assembly sections are transformed into ELF sections. Not all ELF sections are +generated from assembly (e.g. __line__). + + +[prev](091.md) +++ [next](093.md) diff --git a/questions/answers/093.md b/questions/answers/093.md new file mode 100644 index 0000000..5dc784f --- /dev/null +++ b/questions/answers/093.md @@ -0,0 +1,18 @@ + +# Question 93 + + +What symbol marks the program entry point? + + +# Answer + + + + +`_start` + + + + +[prev](092.md) +++ [next](094.md) diff --git a/questions/answers/094.md b/questions/answers/094.md new file mode 100644 index 0000000..9b7b975 --- /dev/null +++ b/questions/answers/094.md @@ -0,0 +1,22 @@ + +# Question 94 + + +Which are the two different kind of libraries? + + +# Answer + + + + +Static and dynamic. + +* Static libraries are the same thing as `.o` files: they are relocatable object +files that will be inlined into the resulting executable by the linker. +* Dynamic libraries are shared object files. They are compiled and linked separately, +but an entity called dynamic linker should perform a special relocation job on them +before they can be executed as a part of some running process. + + +[prev](093.md) +++ [next](095.md) diff --git a/questions/answers/095.md b/questions/answers/095.md new file mode 100644 index 0000000..f117359 --- /dev/null +++ b/questions/answers/095.md @@ -0,0 +1,16 @@ + +# Question 95 + + +Is there a difference between a static library and a relocatable object file? + + +# Answer + + + +Usually, no. The static libraries in form of `.a` file are just archives of +multiple `.o` files. + + +[prev](094.md) +++ [next](096.md) diff --git a/questions/answers/097.md b/questions/answers/097.md new file mode 100644 index 0000000..49a9e04 --- /dev/null +++ b/questions/answers/097.md @@ -0,0 +1,19 @@ + +# Question 97 + + +Is the `TF` flag cleared automatically when entering interrupt handlers? +Refer to [Intel 64 and IA-32 Architectures Software Developer's Manual]. + + +# Answer + + + + +It depends on the interrupt descriptors (aka __gates__). There are two types of them: trap gates and interrupt gates. +For _interrupt gates_ the interrupt handling is automatically disabled once CPU enters the interrupt handler. + + + +[prev](096.md) +++ [next](098.md) diff --git a/questions/answers/098.md b/questions/answers/098.md new file mode 100644 index 0000000..5b0bfc4 --- /dev/null +++ b/questions/answers/098.md @@ -0,0 +1,29 @@ + +# Question 98 + + +What is an interrupt? + + +# Answer + + + + +This is a controlled violation of the sequential execution of a program. +Interrupts allows one to change program execution order based on events external to +the program itself. + +After a signal (external or internal) is caught, a program’s execution is suspended, some +registers are saved, and the CPU starts executing a special routine to handle the situation. Following are +exemplary situations when an interrupt occurs (and an appropriate piece of code is executed to handle it): +* A signal from an external device (external interrupt). +* Zero division (internal interrupt). +* Invalid instruction (when CPU failed to recognize an instruction by its binary +representation -- internal interrupt). +* An attempt to execute a privileged instruction in a non-privileged mode (internal interrupt). + + + + +[prev](097.md) +++ [next](099.md) diff --git a/questions/answers/099.md b/questions/answers/099.md new file mode 100644 index 0000000..27b69a6 --- /dev/null +++ b/questions/answers/099.md @@ -0,0 +1,17 @@ + +# Question 99 + + +What is IDT? + + +# Answer + + + +A system table that holds __interrupt descriptors__ (also called __gates__). Each +of them holds the interrupt handler address and some additional information. Refer to the Figure 6-3 on page 94 to see its structure. + + + +[prev](098.md) +++ [next](100.md) diff --git a/questions/answers/100.md b/questions/answers/100.md new file mode 100644 index 0000000..621997b --- /dev/null +++ b/questions/answers/100.md @@ -0,0 +1,16 @@ + +# Question 100 + + +What does setting IF change? + + +# Answer + + + +If IF = 1, the interrupts are accepted and handled. If IF = 0, interrupts are +ignored (except for Non-Maskable Interrupts). + + +[prev](099.md) +++ [next](101.md) diff --git a/questions/answers/102.md b/questions/answers/102.md new file mode 100644 index 0000000..ae5813e --- /dev/null +++ b/questions/answers/102.md @@ -0,0 +1,17 @@ + +# Question 102 + + +In which situations does the #PF error occur? + + +# Answer + + + +* When the page is not in physical memory and should be loaded from file (data, +code or or swap file). +* When accessing forbidden addresses. + + +[prev](101.md) +++ [next](103.md) diff --git a/questions/answers/103.md b/questions/answers/103.md new file mode 100644 index 0000000..3a055ab --- /dev/null +++ b/questions/answers/103.md @@ -0,0 +1,19 @@ + +# Question 103 + + +How is #PF error related to the swapping? How does the operating system +use it? + + +# Answer + + + +When a page is swapped out to disk, the `P` bit in the relevant __page table entry__ +is set to zero, because the page is not present in physical memory anymore. +Accessing addresses on this page results in a page fault exception, which enables +the operating system to load the page contents into memory. + + +[prev](102.md) +++ [next](104.md) diff --git a/questions/answers/104.md b/questions/answers/104.md new file mode 100644 index 0000000..ceb7ff5 --- /dev/null +++ b/questions/answers/104.md @@ -0,0 +1,15 @@ + +# Question 104 + + +Can we implement system calls using interrupts? + + +# Answer + + + +Yes, we can actually implement system calls using any instruction that results in an interrupt. Before `syscall` was introduced, `int 0x80` was used to access system calls on Linux, but in reality the choice is arbitrary. We can even use incorrectly encoded instruction to do it, because it results in #UD exception. + + +[prev](103.md) +++ [next](105.md) diff --git a/questions/answers/105.md b/questions/answers/105.md new file mode 100644 index 0000000..d27ddc3 --- /dev/null +++ b/questions/answers/105.md @@ -0,0 +1,16 @@ + +# Question 105 + + +Why do we need a separate instruction to implement system calls? + + +# Answer + + + +Because it is faster than interrupts: it uses always the same routine to access +the system calls handler, and it does not need to use IDT. + + +[prev](104.md) +++ [next](106.md) diff --git a/questions/answers/107.md b/questions/answers/107.md new file mode 100644 index 0000000..62202c6 --- /dev/null +++ b/questions/answers/107.md @@ -0,0 +1,15 @@ + +# Question 107 + + +What is the purpose of interrupt stack tables? + + +# Answer + + + +To provide good, well-formed stacks for interrupt handlers. This can be more robust. + + +[prev](106.md) +++ [next](108.md) diff --git a/questions/answers/108.md b/questions/answers/108.md new file mode 100644 index 0000000..3dd3190 --- /dev/null +++ b/questions/answers/108.md @@ -0,0 +1,20 @@ + +# Question 108 + + +Does a single thread application have only one stack? + + +# Answer + + + +No, the application has a user stack per thread, but it also has a kernel stack +per thread. Kernel can not trust user `rsp` value to be good and need its own +separate stack for when e.g. the application performs system calls. + +A more profound explanation can be seen at: +[https://stackoverflow.com/questions/12911841/kernel-stack-and-user-space-stack](https://stackoverflow.com/questions/12911841/kernel-stack-and-user-space-stack) + + +[prev](107.md) +++ [next](109.md) diff --git a/questions/answers/109.md b/questions/answers/109.md new file mode 100644 index 0000000..a6ef95c --- /dev/null +++ b/questions/answers/109.md @@ -0,0 +1,16 @@ + +# Question 109 + + +What kinds of input and output mechanism does Intel 64 provide? + + +# Answer + + + +* `in` and `out` instructions to work with input/output ports +* memory mapped I/O + + +[prev](108.md) +++ [next](110.md) diff --git a/questions/answers/110.md b/questions/answers/110.md new file mode 100644 index 0000000..53be422 --- /dev/null +++ b/questions/answers/110.md @@ -0,0 +1,15 @@ + +# Question 110 + + +What is a model specific register? + + +# Answer + + + +A register that appears as a non standard extension used by a specific processor model. It can then become part of the standard and be usable in all newer processors. + + +[prev](109.md) +++ [next](111.md) diff --git a/questions/answers/111.md b/questions/answers/111.md new file mode 100644 index 0000000..c08344a --- /dev/null +++ b/questions/answers/111.md @@ -0,0 +1,21 @@ + +# Question 111 + + +What are the shadow registers? + + +# Answer + + + +A register that is not directly accessible but that is used as a cache for a +certain memory value. It can be used implicitly by CPU instead of reading the +said value from memory. + +For example, the current segment descriptors that correspond to the entries in GDT pointed +at by `cs`, `ds`, `ss` are stored in shadow registers to prevent reading them from +GDT at every memory access. + + +[prev](110.md) +++ [next](112.md) diff --git a/questions/answers/112.md b/questions/answers/112.md new file mode 100644 index 0000000..be65273 --- /dev/null +++ b/questions/answers/112.md @@ -0,0 +1,20 @@ + +# Question 112 + + +How are the model specific registers used in the system call mechanism? + + +# Answer + + + +To perform `syscall` the CPU: + +* Loads cs from `STAR`; +* Changes `rflags` with regards to `SFMASK`; +* Saves `rip` into `rcx`; and +* Initializes rip with `LSTAR` value and takes new `cs` and `ss` from `STAR`. + + +[prev](111.md) +++ [next](113.md) diff --git a/questions/answers/113.md b/questions/answers/113.md new file mode 100644 index 0000000..69114c0 --- /dev/null +++ b/questions/answers/113.md @@ -0,0 +1,16 @@ + +# Question 113 + + Which registers are used by `syscall` instruction? + + +# Answer + + + +* `STAR`, `SFMASK`, `LSTAR`; +* `rcx` and `r11` are used to save old `rip` and `rflags` values. + + + +[prev](112.md) +++ [next](114.md) diff --git a/questions/answers/120.md b/questions/answers/120.md new file mode 100644 index 0000000..963487d --- /dev/null +++ b/questions/answers/120.md @@ -0,0 +1,18 @@ + +# Question 120 + + +Look the documentation for commands `sete`, `setl` and their counterparts. + + + +# Answer + + + +Use the volume 2 of [Intel 64 and IA-32 Architectures Software Developer's Manual]. These command allow you to set the +register content to 0 or 1 based on condition instead of making a jump (`je`, `jl` etc.) + + + +[prev](119.md) +++ [next](121.md) diff --git a/questions/answers/122.md b/questions/answers/122.md new file mode 100644 index 0000000..32db60b --- /dev/null +++ b/questions/answers/122.md @@ -0,0 +1,19 @@ + +# Question 122 + + +Should we allocate Forth cells in `.data` section, or are there better +options? + + +# Answer + + + + +By default these cells are not initialized, so it is safe to allocate them in +.bss instead. It means that they will occupy no place in the executable file +itself, so its size on disk is kept small. + + +[prev](121.md) +++ [next](123.md) diff --git a/questions/answers/123.md b/questions/answers/123.md new file mode 100644 index 0000000..26783cc --- /dev/null +++ b/questions/answers/123.md @@ -0,0 +1,18 @@ + +# Question 123 + + +Why do we need a separate case for `branch` and `0branch`? + + +# Answer + + + +By default, in compile mode when we see a number `n` we emit `lit n` so that +the number would not be interpreted as a word address. However, `0branch` and +`branch` are unique because they accept a number as an operand. So, they should +be translated into e.g. `0branch 42` directly and not `0branch lit 42`. + + +[prev](122.md) +++ [next](124.md) diff --git a/questions/answers/124.md b/questions/answers/124.md new file mode 100644 index 0000000..549f964 --- /dev/null +++ b/questions/answers/124.md @@ -0,0 +1,15 @@ + +# Question 124 + + +What is a model of computation? + + +# Answer + + + +A set of atomic operations that are used to construct algorithms. + + +[prev](123.md) +++ [next](125.md) diff --git a/questions/answers/125.md b/questions/answers/125.md new file mode 100644 index 0000000..b364a55 --- /dev/null +++ b/questions/answers/125.md @@ -0,0 +1,25 @@ + +# Question 125 + + +Which models of computation do you know? + + +# Answer + + + +So far we did study the von Neumann model of computations "on steroids", with +numerous extensions. The model of computation of most imperative languages +(C, Java, D, python etc) derives from it. We have also studied stack machines, +such as Forth. It relies on stack so heavily that it is usually put in another +class, despite resembling von Neumann model from many sides. + +In this book we will also study Finite State Machines and Formal Grammars. + +Besides, you might have had experience with Prolog and Functional Programming (which is +based on Lambda Calculus), or event-driven frameworks, which are all of different kind. + + + +[prev](124.md) +++ [next](126.md) diff --git a/questions/answers/126.md b/questions/answers/126.md new file mode 100644 index 0000000..8f50c10 --- /dev/null +++ b/questions/answers/126.md @@ -0,0 +1,34 @@ + +# Question 126 + + +What is a finite state machine? + + +# Answer + + + +__Deterministic finite state machine__ (deterministic finite automaton) is an +abstract machine that acts on input string, following some rules. +The following parts should be provided: + +1. A set of states. +2. Alphabet -- a set of symbols that can appear in the input string. +3. A selected start state. +4. One or multiple selected end states +5. Rules of transition between states. Each rule consumes a symbol from input string. +Its action can be described as: "if automaton is in state S and an input symbol C +occurs, the next current state will be Z." + +The non-deterministic machine differs in two poins: +* In any state, there can be _multiple_ transitions for the _same_ input symbol. In case of such transitions we get _multiple_ active states. +* When an input symbol is analyzed, the transitions from all active states are +performed. When there is no rule to follow from one of the active states, this +state "dies" and becomes inactive as if FSM did not reach it. +* FSM accepts an input string if at least one execution branch has led us to a +final state. + + + +[prev](125.md) +++ [next](127.md) diff --git a/questions/answers/127.md b/questions/answers/127.md new file mode 100644 index 0000000..dd3dfd3 --- /dev/null +++ b/questions/answers/127.md @@ -0,0 +1,16 @@ + +# Question 127 + + +When are the finite state machines useful? + + +# Answer + + + +Search (and replace) patterns in text, systems that should react to global +events, robust systems which should be verifiable using model checking techniques. + + +[prev](126.md) +++ [next](128.md) diff --git a/questions/answers/128.md b/questions/answers/128.md new file mode 100644 index 0000000..29bc7fc --- /dev/null +++ b/questions/answers/128.md @@ -0,0 +1,28 @@ + +# Question 128 + + +What is a finite automaton? + + +# Answer + + + +It is the synonym for "Finite State Machine". + +__Deterministic finite state machine__ (deterministic finite automaton) is an +abstract machine that acts on input string, following some rules. +The following parts should be provided: + +1. A set of states. +2. Alphabet -- a set of symbols that can appear in the input string. +3. A selected start state. +4. One or multiple selected end states +5. Rules of transition between states. Each rule consumes a symbol from input string. +Its action can be described as: "if automaton is in state S and an input symbol C +occurs, the next current state will be Z." + + + +[prev](127.md) +++ [next](129.md) diff --git a/questions/answers/129.md b/questions/answers/129.md new file mode 100644 index 0000000..a9f6c84 --- /dev/null +++ b/questions/answers/129.md @@ -0,0 +1,16 @@ + +# Question 129 + + +What is a regular expression? + + +# Answer + + + +A textual representation of a finite state machine used to perform pattern search or substitutions. + + + +[prev](128.md) +++ [next](130.md) diff --git a/questions/answers/130.md b/questions/answers/130.md new file mode 100644 index 0000000..12e175e --- /dev/null +++ b/questions/answers/130.md @@ -0,0 +1,15 @@ + +# Question 130 + + +How are regular expressions and finite automatons connected? + + +# Answer + + + +Regular expressions are just a way to describe finite automatons without drawing diagrams. + + +[prev](129.md) +++ [next](131.md) diff --git a/questions/answers/134.md b/questions/answers/134.md new file mode 100644 index 0000000..5312fb3 --- /dev/null +++ b/questions/answers/134.md @@ -0,0 +1,17 @@ + +# Question 134 + + +What is the implementation difference between embedded and colon words? + + +# Answer + + + +The `implementation` field of a colon word header is a link to `docol`. +For embedded words it leads directly to the piece of assembly code that +implements them. + + +[prev](133.md) +++ [next](135.md) diff --git a/questions/answers/135.md b/questions/answers/135.md new file mode 100644 index 0000000..5a44656 --- /dev/null +++ b/questions/answers/135.md @@ -0,0 +1,14 @@ + +# Question 135 + + +Why are two stacks used in Forth? + + +# Answer + + + +One is used for computations, other is used for return addresses. It can also be used to emulate local variables. + +[prev](134.md) +++ [next](136.md) diff --git a/questions/answers/136.md b/questions/answers/136.md new file mode 100644 index 0000000..57341e6 --- /dev/null +++ b/questions/answers/136.md @@ -0,0 +1,16 @@ + +# Question 136 + + +Which are two distinct modes that Forth is operating in? + + +# Answer + + + +Compilation and interpretation mode. + + + +[prev](135.md) +++ [next](137.md) diff --git a/questions/answers/137.md b/questions/answers/137.md new file mode 100644 index 0000000..8116a37 --- /dev/null +++ b/questions/answers/137.md @@ -0,0 +1,16 @@ + +# Question 137 + + +Why does the immediate flag exist? + + +# Answer + + + +For a word marked as "immediate" in the dictionary, Forth always interprets it +even in compilation mode. + + +[prev](136.md) +++ [next](138.md) diff --git a/questions/answers/140.md b/questions/answers/140.md new file mode 100644 index 0000000..4f90dc0 --- /dev/null +++ b/questions/answers/140.md @@ -0,0 +1,17 @@ + +# Question 140 + + +What is the purpose of `next`? + + +# Answer + + + +It selects the next instruction based on `PC` value and performs jump to its +implementation (which `docol` for colon words). + + + +[prev](139.md) +++ [next](141.md) diff --git a/questions/answers/141.md b/questions/answers/141.md new file mode 100644 index 0000000..61461af --- /dev/null +++ b/questions/answers/141.md @@ -0,0 +1,16 @@ + +# Question 141 + + +What is the purpose of `docol`? + + +# Answer + + + +It sets up the return address and starts working through execution tokens +that constitute the colon word implementation. + + +[prev](140.md) +++ [next](142.md) diff --git a/questions/answers/142.md b/questions/answers/142.md new file mode 100644 index 0000000..01a4f8f --- /dev/null +++ b/questions/answers/142.md @@ -0,0 +1,15 @@ + +# Question 142 + + +What is the purpose of `exit`? + + +# Answer + + + +It takes the return address from the stack of return addresses and puts it into `PC`. + + +[prev](141.md) +++ [next](143.md) diff --git a/questions/answers/143.md b/questions/answers/143.md new file mode 100644 index 0000000..dbe161a --- /dev/null +++ b/questions/answers/143.md @@ -0,0 +1,19 @@ + +# Question 143 + + +When an integer literal is encountered, do interpreter and compiler +behave alike? + + +# Answer + + + +No, the interpreter puts it into stack directly, while compiler should emit +`lit` instruction first. An exception would be when a number occurs immediately +after `branch` or `0branch` words. + + + +[prev](142.md) +++ [next](144.md)