ComputersProgramming

"What is this" came on the stack, "what is it" came back: the abstract foundation of reality

Perhaps in some future the computing business will forget about the zeros and ones, and the processors will not operate bytes and words, but so far everything is represented by the binary world and lives by its rules. What is the stack and where it is applied - most likely, it will become absolutely not clear. Even at the beginning of its appearance, the first processor had registers, and the logic of its work needed memory. As a result of implementing simple ideas, the stack "what it is" has become de facto "so necessary".

Functions, processor, binary logic

The processor manages memory and implements the logic of cyclic code execution. A program is one or a set of functions that represent a sequence of operations: select something, do so, put something there. The operating system is also a code more responsible: it is instructed to execute and monitor other programs.

Actually, the function (an independent element of the algorithm) is just a sequence of binary operations. The program differs from the function in that it implements itself and coordinates other parts of the code.

The algorithm is designed to develop as a sequence of separate independent elements. Each one performs its own (usually only one) function - it's convenient for debugging, graphically, practically. Such programming makes it possible to simplify the development process, create algorithms libraries and use them in other projects.

Transfer and Return Management

The program calls the function and, passing it the data, expects to get the result. So the execution of another part of the code is initiated from the outside, therefore the control return must be performed on the next operation after the call. This mechanism ensures the order of execution of the code and the achievement of the result of the program as a whole.

The code is loaded into memory and executed sequentially. To call a function (another piece of code), a stack is used. What is it? The memory (and the pointer to it), which differs from the usual one in that each next element is placed above the previous one. Therefore, to get everyone below it, you need to take and work out everything that is above it. The pointer always points to the current position on the stack.

Initially, the return address is on the stack - the address of the next operation after the call. Then all the data necessary for the called function is placed there. The called function selects the data, processes it, generates the result, and returns control over the last element of the stack. The command: "stack that it" moves the pointer to the previous given, and the selected "it" goes into processing.

Registers AX, BX, CX, DX, EX have become a kind of symbol of the era of the beginning of the information era, but the SP and SS are its main talisman. How is the stack used in programming? Examples of the past will not become monuments of the architecture of the beginning of the era. The stack came into the binary world along with the words "function" and "recursion" and disappeared into the general logic of programming practice development.

Serving data to decide what to do

The stacking mechanism allows multiple calls to various parts of the code, including recursion: a function call itself. There are natural limitations: the size of the memory for the stack and the code must be sufficient. If the program is correct, then its execution will be stable, the transfer / return control - accurate.

The stack is filled, as the plates fall into a pile, which is sent to serve the table. The fate of plates, that is, their filling, is decided in the place where it is transferred. According to the logic of interaction, the team "stack what it is" gives a pre-agreed given between the one who called and the one whom he called. After the process is completed, it is important to return control to the address next to sending the stack to the table.

Very simple and effective logic. What is done on the table, how the decision is made - the function of the function, how it will deal with the received data - its concern, on which table it will send its stack of data - its concern, the main thing is that management always returns to the next operation after the call. A function can call itself only if it allows recursion, and recursion is possible only if the data is put on the stack.

Fundamental abstractions

When the everyday and practical becomes the basis of a virtual perspective, one can reasonably rely on the objectivity and long life of the latter. A stack of cymbals gave life to the stack, and the stack provided the work of processors, operating systems, programs, functions and the scope of high technologies in general.

A classic case where simple became the basis, but a rare case when it can be estimated without empty arguments about syntax, semantics, programming mechanisms and priorities in the struggle of languages for survival.

The variable, as was a memory cell, remained so to this day, only now the ideas about it have changed. Having confidently passed through the heat of strict typification, they now say: something can be anything and take anything in real memory, because that is absolutely not important at all.

Assignment, condition, loop, block ... operators are much less transformed in the semantic plan, but the syntax has long been irrelevant. The struggle of programming languages for ideals did not give a chance to win one of them. The tool (the compiler / interpreter / shell) must simply work, be stable and fully functional, and how and what to write / use is the concern of the programmer, not the language's author.

Stack has acquired a new meaning in this global process of developing representations and technologies. Variables in the form in which they are convenient, are layered on each other, and algorithms and operators are included in each other. Often you can hear about the protocol stack, when one provides the work of another.

Stack, functionality and recursion are not synonymous at all, but they perfectly complement each other, allowing you to create unique options for presenting and processing information.

Similar articles

 

 

 

 

Trending Now

 

 

 

 

Newest

Copyright © 2018 en.atomiyme.com. Theme powered by WordPress.