Assembler Registers: Types, Purpose, and Features of Commands

Due to the low-level programming language that controls them, processor cells, also called assembler registers, represent a block of free elements in memory. Their characteristic feature is ultrafast memory access. Most often, registers are used during execution of processor instructions and are not available to the programmer. For example, while fetching the next command number from the available superfast memory, its code in the binary system is placed in the register.

It is not possible to access the register directly. In addition, there are a number of available memory blocks, however, you can access them only from the shell of the operating system. These include control segment registers, as well as shadow descriptor systems. These registers are exclusively used by OS developers in their work.

Register structure in assembler

Types of Registers

For different needs, different Assembler registers are used during programming. Use them depending on the purpose. For example, the counter register is used to organize both simple and nested loops. The following are the main types of assembler registers:

  • General purpose registers.
  • Index registers.
  • Pointer Registers.
  • Segmented memory blocks.
  • Registers of flags.

Virtually all registers occupy 32 bits in memory. That is, they can contain numbers from zero to 4294967295. Some of the registers are divided into several parts of 16 and 8 bits. This allows you to control either part of the memory block, or the entire cell, writing only part of the data into it.

Memory management commands

Assembler registers were named according to the functions performed:

  • EAX - Accumulator of the battery register;
  • EBX - Base - base;
  • ECX - Counter - responsible for the expense;
  • EDX - Data - block of data cells;
  • ESI - Source Index - source register;
  • EDI - Destination Index - receiver register;
  • ESP - Pointer of stack - pointer to the stack;
  • EBP - Base Pointer - pointer to the bottom of the stack.

Features of using registers

It is worth considering that each of the indicated registers can be used not only for entering data. For example, you can enter any decimal number in the base register and use it as a counter. However, at the same time, it is undesirable to use memory blocks for these purposes that correspond to pointers - ESP and EBP, as this may cause problems with access to cells of an abstract data type. The purpose of assembler registers is to store some information, for which any kind of information can be used.

ASM code and listing view

General purpose registers

This type of registers was created to save data after computational operations. In fact, they can use the mov command to enter information in any form and number system: binary, octal, decimal or hexadecimal. Another name is assembler data registers. The list of general purpose registers assembler include:

  • EAX (accumulator) register accumulation. It consists of three low-order blocks of 8 bits: AX, AN, AL. If necessary, you can refer to the two lower blocks.
  • (base) - a data block that is responsible for the base. Just like all general-purpose registers, it consists of two lower-order sections of 8 bits and one sixteen-bit one. Thus, in one register, you can put several numerical values ​​at once.
  • ECX (counter) - is responsible for the counter. Used during run times. The loop command does not work without it. It consists of two parts, one of which includes two eight-bit blocks of CH and CL.
  • EDX - Data - is required for operations to accurately determine the address in RAM for input and output functions. In addition, data can be placed in this register for redirection for use in procedures and templates.
    Work with registers in 64-bit version

Registers pointers

To work with the stack, assembler developers have two types of registers. To access them, an operation is added to the vertex pointer of the abstract type of bit values ​​of a certain data type, which was pushed onto the stack. All calculations are carried out manually. Thus, a large amount of data is stored and transferred to subprograms - procedures and arrays. Among the register registers in assembler allocate:

CPU and register structure
  • The ESP register is a pointer to the top of the stack. It always contains the address of the first element that was pushed onto the processor cache. If necessary, can be filled with other data. Includes a 16-bit low register SP.
  • Register EBP (Base Pointer) - is a block of memory cells required to address the data contained in the stack. This greatly facilitates access to all data and variables. Includes low-order BP.

Index registers

Index memory blocks are required for advanced indexing. In addition, they participate in some arithmetic operations and processing byte strings - a sequence of bytes containing an arbitrary value. The assembler includes two registers that are responsible for indexing ESI and EDI. We describe them:

  • ESI (Source index) includes the source index (the place where the data comes from) and is needed for some actions on byte strings;
  • An EDI (Destination Index) is required to record the results of calculations. Also used for part of string actions. Partially linked to the ES segment register.

Segment registers

They are the first blocks in memory. Called current segments. The software is allowed to allocate more than four blocks of memory. However, it is imperative to enter the addresses of the blocks in the memory cells between the segment registers. This type of memory blocks is strictly specific, so it is impossible to fill them with a separate type of data. The order of register blocks in memory may vary. Segment registers are stored in random order in random memory locations.

  • The CS code register in its usual form contains the address of the beginning of the software code segment (the beginning of the machine code presentation). Thus, the transition is carried out by commands due to the IP command pointer.
  • The data register contains the address of the data that the program processes at the start of the start. The movement through the data is carried out due to the offset, which is recorded in the EIP register.
  • Stack Segment (ESS) is needed to save the beginning of an abstract data type segment.
  • Extra segment is an auxiliary register that contains an empty area for writing data during some operations on byte strings. May contain information similar to a data register.

Command pointer register

Communication between memory units

This type refers to the team. Using this pointer, the assembler register is displayed in the listing. Includes data on the shift to the next command relative to the previous one. When developing software, it is practically not used, but it is required to view the code execution listing. This way they track errors.

Assembler flags register

Responsible for the current state of the central processor. It consists of 16 bits, of which only 9 can be occupied. This block of memory is filled after execution, skipping or an error code as a result of the previous command. In addition, part of the bits is used by the processor and can be initialized and deleted by means of a specific system of instructions. Thus, the command system is managed.

Source: https://habr.com/ru/post/K4675/


All Articles