Lecture notes, cheat sheets
Computer science and information technology. Registers (lecture notes) Directory / Lecture notes, cheat sheets Table of contents (expand) LECTURE No. 14. Assembler 1. About assembler Once upon a time, assembler was a language without knowing which it was impossible to make a computer do anything useful. Gradually the situation changed. More convenient means of communication with a computer appeared. But unlike other languages, assembler did not die; moreover, it could not do this in principle. Why? In search of an answer, we will try to understand what assembly language is in general. In short, assembly language is a symbolic representation of machine language. All processes in the machine at the lowest, hardware level are driven only by commands (instructions) of the machine language. From this it is clear that, despite the common name, the assembly language for each type of computer is different. This also applies to the appearance of programs written in assembler, and the ideas that this language is a reflection of. Really solving hardware-related problems (or, even more, hardware-related ones, such as speeding up a program, for example) is impossible without knowledge of assembler. A programmer or any other user can use any high-level tools up to programs for building virtual worlds and, perhaps, not even suspect that the computer is actually executing not the commands of the language in which its program is written, but their transformed representation in the form of a boring and dull sequence commands of a completely different language - machine language. Now imagine that such a user has a non-standard problem. For example, his program must work with some unusual device or perform other actions that require knowledge of the principles of computer hardware. No matter how good the language in which the programmer wrote his program is, he cannot do without knowing the assembler. And it is no coincidence that almost all compilers of high-level languages contain means of connecting their modules with modules in assembler or support access to the assembler programming level. A computer is made up of several physical devices, each of which is connected to one unit, called the system unit. To understand their functional purpose, let's look at the block diagram of a typical computer (Fig. 1). It does not pretend to absolute accuracy and aims only to show the purpose, relationship and typical composition of the elements of a modern personal computer. Rice. 1. Structural diagram of a personal computer 2. Software model of the microprocessor In today's computer market, there is a wide variety of different types of computers. Therefore, it is possible to assume that the consumer will have a question about how to evaluate the capabilities of a particular type (or model) of a computer and its distinctive features from computers of other types (models). To bring together all the concepts that characterize a computer in terms of its functional program-controlled properties, there is a special term - computer architecture. For the first time, the concept of computer architecture began to be mentioned with the advent of third-generation machines for their comparative evaluation. It makes sense to start learning the assembly language of any computer only after finding out what part of the computer is left visible and available for programming in this language. This is the so-called computer program model, part of which is the microprocessor program model, which contains thirty-two registers, more or less available for use by the programmer. These registers can be divided into two large groups: 1) 6 user registers; 2) 16 system registers. 3. User registers As the name implies, user registers are called because the programmer can use them when writing his programs. These registers include (Fig. 2): 1) eight 32-bit registers that can be used by programmers to store data and addresses (they are also called general purpose registers (RON)): eax/ax/ah/al; ebx/bx/bh/bl; edx/dx/dh/dl; ecx/cx/ch/cl; ebp/bp; esi/si; edi/di; esp/sp. 2) six segment registers: cs, ds, ss, es, fs, gs; 3) status and control registers: flag register eflags/flags; eip/ip command pointer register. Rice. 2. User registers Many of these registers are given with a slash. These are not different registers - they are parts of one large 32-bit register. They can be used in the program as separate objects. 4. General registers All registers of this group allow you to access their "lower" parts. Only the lower 16- and 8-bit parts of these registers can be used for self-addressing. The upper 16 bits of these registers are not available as independent objects. Let's list the registers belonging to the group of general purpose registers. Since these registers are physically located in the microprocessor inside the arithmetic logic unit (AL>), they are also called ALU registers: 1) eax/ax/ah/al (Accumulator register) - battery. Used to store intermediate data. In some commands, the use of this register is required; 2) ebx/bx/bh/bl (Base register) - base register. Used to store the base address of some object in memory; 3) ecx/cx/ch/cl (Count register) - counter register. It is used in commands that perform some repetitive actions. Its use is often implicit and hidden in the algorithm of the corresponding command. For example, the command for organizing the loop loop, in addition to transferring control to a command located at a certain address, analyzes and decrements the value of the esx/cx register by one; 4) edx/dx/dh/dl (Data register) - data register. Just like the eax/ax/ah/al register, it stores intermediate data. Some commands require its use; for some commands this happens implicitly. The following two registers are used to support the so-called chain operations, i.e. operations that sequentially process chains of elements, each of which can be 32, 16 or 8 bits long: 1) esi/si (Source Index register) - source index. This register in chain operations contains the current address of the element in the source chain; 2) edi/di (Destination Index register) - index of the receiver (recipient). This register in chain operations contains the current address in the destination chain. In the architecture of the microprocessor at the hardware and software level, such a data structure as a stack is supported. To work with the stack in the microprocessor instruction system there are special commands, and in the microprocessor software model there are special registers for this: 1) esp/sp (Stack Pointer register) - stack pointer register. Contains a pointer to the top of the stack in the current stack segment. 2) ebp/bp (Base Pointer register) - stack frame base pointer register. Designed to organize random access to data inside the stack. The use of hard pinning of registers for some instructions makes it possible to encode their machine representation more compactly. Knowing these features will, if necessary, save at least a few bytes of memory occupied by the program code. 5. Segment registers There are six segment registers in the microprocessor software model: cs, ss, ds, es, gs, fs. Their existence is due to the specifics of the organization and use of RAM by Intel microprocessors. It lies in the fact that the microprocessor hardware supports the structural organization of the program in the form of three parts, called segments. Accordingly, such an organization of memory is called segmented. In order to indicate the segments to which the program has access at a particular point in time, segment registers are intended. In fact (with a slight correction) these registers contain the memory addresses from which the corresponding segments begin. The logic of processing a machine instruction is constructed in such a way that addresses in well-defined segment registers are implicitly used when fetching an instruction, accessing program data or accessing the stack. The microprocessor supports the following types of segments. 1. Code segment. Contains program commands. To access this segment, the cs register (code segment register) is used - the segment code register. It contains the address of the machine instruction segment that the microprocessor has access to (i.e., these instructions are loaded into the microprocessor pipeline). 2. Data segment. Contains the data processed by the program. To access this segment, the ds (data segment register) register is used - a segment data register that stores the address of the data segment of the current program. 3. Stack segment. This segment is a region of memory called the stack. The microprocessor organizes work with the stack according to the following principle: the last element written to this area is selected first. To access this segment, the ss register (stack segment register) is used - the stack segment register containing the address of the stack segment. 4. Additional data segment. Implicitly, the algorithms for executing most machine instructions assume that the data they process is located in the data segment, the address of which is in the ds segment register. If one data segment is not enough for the program, then it has the opportunity to use three more additional data segments. But unlike the main data segment, whose address is contained in the ds segment register, when using additional data segments, their addresses must be specified explicitly using special segment redefinition prefixes in the command. Addresses of additional data segments must be contained in the registers es, gs, fs (extension data segment registers). 6. Status and control registers The microprocessor includes several registers that constantly contain information about the state of both the microprocessor itself and the program whose instructions are currently loaded onto the pipeline. These registers include: 1) flag register eflags/flags; 2) eip/ip command pointer register. Using these registers, you can get information about the results of command execution and influence the state of the microprocessor itself. Let us consider in more detail the purpose and contents of these registers. 1. eflags/flags (flag register) - flag register. The bit depth of eflags/flags is 32/16 bits. Individual bits of this register have a specific functional purpose and are called flags. The lower part of this register is exactly the same as the flags register for 18086. Figure 3 shows the contents of the eflags register. Rice. 3. The contents of the eflags register Depending on how they are used, the flags of the eflags/flags register can be divided into three groups: 1) eight status flags. These flags may change after machine instructions have been executed. The status flags of the eflags register reflect the specifics of the result of the execution of arithmetic or logical operations. This makes it possible to analyze the state of the computational process and respond to it using conditional jump commands and subroutine calls. Table 1 lists the status flags and their purpose. 2) one control flag. Denoted df (Directory Flag). It is located in bit 10 of the eflags register and is used by chained commands. The value of the df flag determines the direction of element-by-element processing in these operations: from the beginning of the string to the end (df = 0) or vice versa, from the end of the string to its beginning (df = 1). There are special commands for working with the df flag: eld (remove the df flag) and std (set the df flag). The use of these commands allows you to adjust the df flag in accordance with the algorithm and ensure that counters are automatically incremented or decremented when performing operations on strings. 3) five system flags. Controls I/O, maskable interrupts, debugging, task switching, and 8086 virtual mode. It is not recommended for application programs to modify these flags unnecessarily, as this will cause the program to terminate in most cases. Table 2 lists the system flags and their purpose. Table 1. Status flagsTable 2. System flags 2. eip/ip (Instraction Pointer register) - instruction pointer register. The eip/ip register is 32/16 bits wide and contains the offset of the next instruction to be executed relative to the contents of the cs segment register in the current instruction segment. This register is not directly accessible to the programmer, but its value is loaded and changed by various control commands, which include commands for conditional and unconditional jumps, calling procedures, and returning from procedures. The occurrence of interrupts also modifies the eip/ip register. Author: Tsvetkova A.V. << Back: Assembler (About assembler. Microprocessor software model. User registers. General purpose registers. Segment registers. Status and control registers) >> Forward: Assembly programs (Assembler program structure. Assembler syntax. Comparison operators. Operators and their precedence. Simplified segment definition directives. Identifiers created by the MODEL directive. Memory models. Memory model modifiers) We recommend interesting articles Section Lecture notes, cheat sheets: ▪ General and clinical immunology. Crib ▪ Surgical diseases. Lecture notes See other articles Section Lecture notes, cheat sheets. Read and write useful comments on this article. Latest news of science and technology, new electronics: The existence of an entropy rule for quantum entanglement has been proven
09.05.2024 Mini air conditioner Sony Reon Pocket 5
09.05.2024 Energy from space for Starship
08.05.2024
Other interesting news: ▪ Video capsule with remote control as an alternative to the endoscope ▪ Where did blue eyes come from ▪ Unmanned aerial vehicles with biohull ▪ Adata Industrial Grade Solid State Drives ISSS332 ▪ Viruses are 10 times stronger in the morning than in the evening News feed of science and technology, new electronics
Interesting materials of the Free Technical Library: ▪ site section Field strength detectors. Article selection ▪ article My Universities. Popular expression ▪ article Head of Operations. Job description ▪ article Mine detector. Encyclopedia of radio electronics and electrical engineering ▪ article Magic tape. Focus Secret
Leave your comment on this article: All languages of this page Home page | Library | Articles | Website map | Site Reviews www.diagram.com.ua |