Last Updated:

What is Assembly language?

Among the low-level programming languages, the Assembly programming language occupies a special place. It is an ideal option for those who want to do programming from the very beginning.

Despite the fact that it belongs to the category of low-level, it is designed for computers and other devices that are designed for a special PC architecture. Conversion of this language is carried out into machine executable code through the use of special software.

Basics of Assembly Mechanics

If we consider the generally accepted basics of syntax that are used for all programming languages, then they do not exist for assembly. But despite this, anyone who is engaged in programming in this language adheres to certain generally accepted approaches. Among these standards, it is worth paying attention to AT&T syntax and Intel syntax.


For each of these standards, a single format for recording is used, which looks like this:


Here, specifically, the assembly instruction is the opcode, which is the mnemonic of the instruction for a particular processor. There may be special prefixes, among which there are often changes in the form of addressing and repetition.

As for the names of registers, constants, addresses located in the RAM of the PC, they act as operands. But at the same time, it is worth paying attention to the fact that there is a difference between the syntax standards, which mainly lies in the order in which operands are listed among themselves in the process of such a procedure as addressing. The instructions that are used are basically the same for all processors that belong to the same architecture.

Assembly Directives

In addition to the fact that the assembly programming language uses commands, it is also possible to apply special directives. They also represent commands, but only those that will not be realistically translated into special machine codes in the future. They can be managed only by means of a special compiler program.

As for their set and the immediate syntax itself, it will be significantly different. This will depend on which compiler is preferred, not the hardware component.

Among the main set of directives, it is worth paying attention to the following:

  • define variables and constants;
  • set the mode in which the compiler will run;
  • manage the parameters of the output file, as well as the organization of the software;
  • Macros
  • various abstractions – from cycles and conditional constructions to functions and design procedures.

Advantages and disadvantages of assembly language

Among the advantages of the assembly programming language, you should pay attention to the following:

  • the amount of redundant code is minimal - this is due to the fact that the number of accesses to memory is small and the number of instructions is not too large. This contributes to the possibility of obtaining a program of not too large size and operational speed;
  • the possibility of obtaining direct access to the equipment: certain PC registers and output-input ports;
  • implementation of the maximum fit for the platform that is necessary (application of technical features of the iron used and special instructions);
  • the ability to create code with the self-modification function - in the future, this is convenient because the user will have the opportunity to change the code during the execution of the program without using an additional interpreter.

If you look at the shortcomings, they are there, albeit in small quantities. These include the following:

  • a huge number of additional and very small commands, huge program codes;
  • readability of the code is at a low level, as well as the occurrence of difficulties in the debugging process;
  • small compatibility between libraries, as well as their small number;
  • inability to port to other types of platforms besides those that are binary compatible with each other.

Assembler: registers


The assembly programming language works with registers, among which it is worth highlighting the following:

General purpose register - this includes 8 registers, in each of which the process of storing no more than 4 bytes of information takes place. Subsequently, such a register can be conditionally divided into 4 or 2 parts, which makes it possible to work with various cells in the future;

Instruction pointer register - in the register of the presented sample, the process of storing only the address of the instruction that should subsequently be executed by the processor takes place. In manual mode, this register is not subject to change, but due to the use of all sorts of procedures and transition commands, it can be influenced;

Register of flags - under such a concept as "flag", it is worth understanding a certain property that the processor is endowed with. In the event that the so-called overflow flag is used, this will indicate that the processor will subsequently be endowed with such a number that it will not be able to fit in the desired memory cell. It will only nest in that cell what will fit.

In other cases, the programmer who is engaged in the process of writing a program will receive a notification that something is not happening as it should be. As for the number of flags, there can be quite a lot of them. Some of them will be used for analysis, while others will affect the procedures carried out related to calculations. They can be changed with your own hands or left unchanged;

Registers of segment type - such registers are used only so that the programmer has the opportunity to work with individual elements of RAM and get free access to any cell that is needed.

Now the volume of such cells is about 32 bits and this is what makes it possible to get full access to RAM with a capacity of 4 GB. For those applications and programs that are created through the use of the Assembly programming language, this is quite enough.

Therefore, considering all that the Assembly programming language operates with, a special place belongs to variables, processor instructions and registers.

Assembler: Macros

In order to provide high-quality modular programming in the Assembler, special macros are used. A macro is a special sequence of instructions that have a name. In this case, macros can be used anywhere, regardless of where they are located. In order to carry out the process of defining macros, the following syntax is used:


In the event that there is a need to call a macro, you need to use the special name of the macro with which it is endowed along with the specific parameters that are necessary. If there is a need to carry out the process of using a certain instruction a large number of times in a row, in this case, a special macro can be introduced into such instructions, which will later be used instead of the standard procedure for writing instructions.

If we give an example, then here it is worth paying attention to the option when there is a need to implement a constant process of displaying special strings of characters on the screen. In order to implement this process, the following sequence of instructions can be applied in the future:


In this case, when it becomes necessary to display certain lines on the screen, these registers should be stored in a special stack in the future. Here it is quite advisable to use several macros at the same time: for data recovery and for their storage.

Assembler: Recursion

Among the procedures that are able to evoke themselves, recursion occupies a special place. Among those recursion options that are used in the Assembly programming language, the following occupy a special place:

  • indirect recursion;
  • direct recursion.

In the event that the process of applying direct recursion occurs, then it is able to cause itself. If we take into account the indirect type recursion, then the appearance of the first procedure automatically causes the second procedure to occur. In this case, the second procedure will on the contrary make a call to the first, since they are interrelated.

A procedure such as recursion is observed, if necessary, in the performance of complex mathematical operations. For example, this includes such a mathematical process as the procedure for calculating the factorial of a number. In this case, the recursive algorithm must necessarily have an ending. If we consider the process of calculating the factorial of the number, then the final stage will be the moment when n = 0.

Assembler: procedures

In the Assembly programming language, subprogrammes and special procedures occupy a special place. This is due to the fact that a huge number of programs that are written in this language are quite voluminous.

Identification of all procedures among themselves occurs by a special name, after which the body of the procedure itself follows. In order to specify the process of completing the procedure, a return statement appears.

The syntax of the procedures used can be found below:


A call from another function of a procedure is made by using a CALL statement that has as an argument the name of the function that is being called.

Assembler: conditions

In the Assembly programming language, the conditions are the instructions of branching and cyclic processes. By using them in your program code, you can change the thread on which commands will be executed.

Among the options for fulfilling the conditions in Assembler, several types can be distinguished:

  • unconditional jump (jump without conditions) - its implementation occurs due to the JMP instruction. In the process of transferring control, the process of executing certain instructions or executing a set of instructions that are completely new can be carried out;
  • conditional jump (jump with a condition) – the execution of procedures occurs through the use of special conditions and will depend on what condition will be set for implementation. Conditional type instructions carry out the process of changing the offset in the register, which facilitates the process of interrupting certain program code.

Assembler: Constants and Variables

For the process of storing variables, a variety of directives for reserving space are proposed for use. In order to allocate disk space, the Assembly programming language uses a special definition directive. It can be used not only for redundancy, but also for the process of bytes initialization.

For data that is initialized, the memory allocation statement will have the following syntax, represented as follows:


The identifier used for the storage space is the variable name itself. For each of the selected variable names, Assembly binds the values over which the offset occurs.

Among the presented forms of definition directives are the following:


Examples of the process of using definition directives can be found below:

Assembly Programming Language

Here it is worth paying attention to the following features:

  • each of the byte characters is stored directly in hexadecimal form;
  • The byte order that is used by the processor is straight;
  • if decimal values are taken, they are automatically converted to a hexadecimal format with a binary equivalent;
  • there is a process of mandatory conversion of negative numbers;
  • in order to represent long and short numbers that have a floating point, they are represented using 64 or 32 bits.

In the following example, you can see how the process of using the definition directive will take place:

In the event that there is a need for a process such as reserving space for data that is not initialized, special redundancy directives are used. Such directives subsequently carry out the process of applying one operand, which will be responsible for the amount of space that will be free and subsequently reserved.

If we consider the directives of the definition, it is worth paying attention to the fact that each of them has a reservation directive associated with them.

Among the forms that can receive reservation directives, it is worth highlighting the following:


In order to define data in the program, several statements can be used simultaneously. For example, it might look like this:


To carry out simultaneous determination of variables, assembler independently performs the allocation of so-called adjacent memory.

For a single value, multiple initializations can be implemented at the same time, which will be done by applying the Times directive. This directive is in great demand when there is a need to work with tables and arrays.

To perform a process such as defining constants, the following directives are used:

  • %assign;
  • EQU;
  • %define.

To define constants, the EQU directive is most often used. The syntax will look like this:

Assembly Programming Language

For example, this may take the form of:


After that, the constant can later be applied in the written program:


The operand can be the following expression:


In the event that there is a need to apply constants of a numeric type, in this situation a directive called %assign will come to the rescue. With its help, you can carry out such a process as overriding, if necessary. To define a constant such as TOTAL, we can give the following example:


After that, directly in the program code itself, if necessary, you can implement its override:


Among all the directives used, this one is one of the most sensitive to the register.
Among the directives that can be applied to both string and numeric constants, %define is used.

It is very similar to exactly the same directive that is used in the process of creating programs in the C language. This directive, along with the above, is quite sensitive to the register and makes it possible to implement such a process as overriding.

Assembler: System Calls

Between the kernel and the users themselves, there must be programming interfaces that are implemented as system calls.

Among the system calls that can be used in the process of using the Assembly programming language, special attention should be paid to Linux calls. In order to implement this process, you need to perform the following actions:

  • enter the number in the EAX register that is answered by a specific system call;
  • in the ECA and EH registers, carry out the process of preserving arguments that meet a specific system call;
  • perform a procedure for calling the necessary interrupts;
  • the result will be published in the first register under the name EAX.

The following 6 registers can be used to use or store system calls:

  • EHS;
  • EVH;
  • ESI;
  • EDX;
  • EBP;
  • EDI.

Considering these registers, it is worth paying attention to the fact that they work with arguments of a sequential type. In the event that the number of arguments exceeds 6 pieces, the cell in which the very first argument is located is automatically stored in the EBH register.

Among the system calls that the user may encounter can be found in the table, which is located below:

Assembly Programming Language

Assembler: Addressing Modes

To process the operands used, a large number of instructions that are created in the Assembler programming language need to implement a process such as addressing. The address of the operand is a certain place where the process of storing data takes place, which in the future will be subject to the processing process.

Naturally, there are instructions that do not need a process such as processing operands. But there is a category of those instructions that may require several treatments at once. If there is a need for several operands, the first will be the used place for storing information, and the source can be taken as the second.

The source will contain information such as the delivery address or the data necessary to perform the delivery. After the operation, the data that was original does not change.

Among the modes used for addressing, the following can be distinguished:

  • direct or direct addressing;
  • register addressing;
  • Memory addressing.

Considering the features of the work of register addressing, it is worth paying attention to the fact that the register contains the operand itself. Based on what the instruction will be applied, the register itself can act as both the first and second operand. For example, it might look like this:


Here you can implement the most efficient processing process, since there is no need for additional memory during the implementation of register processing.

An expression or a certain constant value can have a straight operand. In the event that direct addressing is used for an instruction in which there are several operands, then the first of them can act as a constant, and the second memory cell or register. The first operand will be responsible for the length of the data. For example, it would look like this:


In the event that the operands are defined in addressing mode, then only direct access to the main memory should be available. But here it is worth paying attention to the fact that this method will be quite slow. By using the initial address of the segment and the offset value, it is possible in the future to determine the location of information in memory as accurately as possible. The offset value is used as the effective address.

If we consider the mode where direct addressing is used, then here the value of the displacement will act as an integral part of a separate instruction. For example, this might be the name of a specific variable. All offset values in automatic mode are determined in Assembler and transferred to a special table, which will later be used when writing programs.

In the process of applying direct addressing, one of the operands will refer to the register, and the other directly to a specific memory cell. For example, it might look like this:


When addressing the so-called forward bias, special arithmetic operators will be used, through the use of which it is possible to carry out the process of changing the address. For variables in which several elements can be located at the same time, the so-called indirect addressing is used. It will be most suitable for a robot with data arrays.

Why do I need assembly programming?

Very often the question arises as to why the Assembly programming language is still used, since it belongs to the category of rather primitive languages. In this case, it is worth paying attention to the fact that it will be almost indispensable in the following areas:

  • drivers;
  • creation of pieces of various operating systems on which it is necessary to implement the highest possible speed of work;
  • the process of programming various embedded processors and microcontrollers;
  • viruses and antivirus software.

But, as practice shows, with the skillful use of the Assembly programming language, a person has the opportunity to create his own website, which even has a forum. But for this, the programmer must have the appropriate qualifications, as he must be aware of all the features in the process of working with this language. But assembly is often used in the case where the capabilities and speed of C ++ seem insufficient to perform the process that is necessary.

At the same time, it is worth understanding that writing in the Assembly programming language is not as easy as it seems at first glance. First of all, this is due to the fact that a person must fully understand the entire architecture of the processor, know how a particular hardware works and at the same time interacts with the processor, be aware of all the necessary instructions that will work for a particular processor that is used, be able to work with information that is fed in byte-byte format, understand that there are certain limitations, which may not lead to the desired functionality of the software being created.

An equally important factor here is also the fact that the process of reading written program codes is quite complicated and this is what leads to the fact that the process of writing a program becomes more complicated and slows down.