Assembler - commands for beginners low-level programmers

All commands can only be executed using machine language. Assembler commands are a symbolic representation of this language. With it, they write small, but very fast programs. But, despite their size, the writing process is very time-consuming.

Assembler commands
Therefore, assembler commands are used to work with the hardware component, or when there is critically insufficient memory for program execution. Therefore, assembler code is executed in the form of subprograms and integrates with high-level code. Since the assembler can vary greatly depending on the type of architecture, you should consider it for a specific case, in this article it is the Win architecture. But the description of assembler commands, as a rule, does not change much, and they can be used both in microcontrollers and in other electronic devices for which assembler is used.
assembler team

Arithmetic Commands Used in Assembler

Despite such a paradox as universality, only 4 arithmetic assembler instructions are and can be used by programmers. Nevertheless, through them, high-level programming languages ​​were created, on which computers, household appliances, telephones, smartphones, laptops, etc. are working. It is possible to work with them, and very successfully. The list of assembler commands is as follows:

  • addition;
  • subtraction;
  • multiplication;
  • division.

Addition

Arithmetic operation, known since school. To use it, you only need to take into account the peculiarity of addition, which is associated with the representation of the added numbers in the memory of the computer itself. The general view of the operation is as follows:

ADD <Cell1 / Register1>, <Cell2 / Register2>

The team takes the numbers from the cells, adds them together and writes them in "Cell1". Now about the conditions for the operation: both numbers from the cell must have the same size. Also, if the register comes first, then everything can be added to it. If the cell comes first, then either the direct operand or the register can be added to it.

description of assembler commands

The description of assembler instructions and their implementation requires a more complete approach than one article can provide. According to assembler commands, despite their miserable number, a huge number of books are being written, which have more than one hundred pages. Therefore, despite the apparent lightness, we recommend that you familiarize yourself with the work that describes the team in more detail, which will allow you to find out all the nuances for different architectures.

Subtraction

This operation is performed according to the same algorithm as the previous one. Even the type of command entry is similar:

SUB <Cell1 / Register1>, <Cell2 / Register2>

assembler arithmetic instructions
The principle of calculation is as follows: value No. 2 is subtracted from No. 1, and recorded in place No. 1. The conditions for passing the operation are exactly the same as the conditions for passing the addition operation.

Multiplication

If the same commands were used for division and addition, both for unsigned and signed numbers, then when multiplying and division, there are different algorithms for them. So, to multiply unsigned numbers, use the following command:

MUL <operand>

assembler command list
The operand specified in the command is one of the factors. The place of the second factor and the place of the result of the operation are fixed in advance, depending on the size of the MUL in bytes. Their location is the topic of a separate article. For sign multiplication, use the command:

IMUL <operand№1>, <operand№2>

You can meet other implementation options, but this one is more understandable and familiar. Two factors are indicated, and the result is placed in operand No. 1. At the same time, operand No. 1 is necessarily a register, and operand No. 2 is a register or memory cell. But other options will also be described:

IMUL <operand # 1>

IMUL <operand # 1 >>, <operand # 2>, <direct operand>

IMUL <operand # 1>, <direct operand>

The first option is similar to MUL in its device, so the rules can be attributed to it here too. The second option allows you to explicitly specify the location - both the result and the factor. The third option indicates the register, which will be the first factor and in which the result of the multiplication will be placed. The direct operand means not specifying a register, but the number by which the operand will be multiplied.

Division

As previously reported, two teams are used for division. For unsigned numbers apply:

DIV <operand>

For signed numbers use the command:

IDIV <operand>

The peculiarity of the use of division commands is that only the divider operand is used, which is a register or memory cell. The divisible number always has its specific location, which depends on the size of the number. The result of the operation also has its place.

Regarding the search and determination of places, one can say the same thing as about multiplication: a separate article is necessary, since the amount of information is very significant.

Useful Conclusion

Also, the NEG <Cell / Register> command should also be included in the category of "relatively useful assembler commands." It translates the character into a number that is in the operand. That's all, we hope that the article helped you understand the arithmetic instructions of assembler.

Useful and incrementing and decrementing operations (increase or decrease the operand by one). To increment an operand, you need to register the following command:

INC <operand>

For decrement should be prescribed:

DEC <operand>

An operand can be a memory cell or register. The exceptional benefit of these operations is that they take up less space for themselves than similar assembler commands offered by addition or subtraction.

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


All Articles