ComputersProgramming

Assembler - a command for beginners of low-level programmers

All commands can only be executed using machine language. Assembler-commands - a symbolic representation of this language. With its help write small, but very fast programs. But, despite their size, the process of writing is very time consuming. Therefore assembler commands are used to work with the hardware component, or when the execution of the program is critically short of memory. Therefore, the assembler code is designed in the form of subroutines and is integrated with the high-level code. Since the assembler can be very different depending on the type of architecture, it should be considered for a particular 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 electronics devices for which assembler is used.

Arithmetic instructions used in assembler

Despite such a paradox, as versatility, only 4 arithmetic assembler commands are and can be used by programmers. But nevertheless, they created high-level programming languages using computers, home appliances, telephones, smartphones, laptops, etc. They can be worked with, and very successfully. The list of assembler commands is as follows:

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

Addition

Arithmetic operation, known from school. For its use, it is necessary to take into account only the singularity of addition, which is connected with the representation of the numbers to be added in the memory of the computer itself. The general form of the operation is as follows:

ADD ,

The team takes numbers from the cells, adds them together and writes them to "Cell1". Now about the conditions of the operation: both numbers from the cell must have the same size. Also, if first there is a register, then you can add everything to it. If a cell first goes, then either the immediate operand or the register can be added to it.

The description of assembler commands and their implementation requires a more complete approach than one article can provide. Assembler commands, despite their meager amount, write a huge number of books that have more than one hundred pages. Therefore, despite the apparent ease, we recommend that you familiarize yourself with a more detailed description of the team work, which will allow you to learn all the nuances for different architectures.

Subtraction

This operation is executed by the same algorithm as the previous one. Even the command record type is similar:

SUB ,

The principle of counting is as follows: from No. 1, the value # 2 is subtracted, and is written to place # 1. The conditions for the operation are exactly the same as the conditions for the addition operation.

Multiplication

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

MUL

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

IMUL ,

You can meet other options for implementation, but this one is more understandable and familiar. Two factors are indicated, and the result is placed in operand # 1. In this case, the register is the operand number 1, and the operand number 2 is the register or memory location. But other options will also be described:

IMUL

IMUL >, ,

IMUL ,

The first option is similar to MUL in its device, so the rules for it can be attributed here. The second option allows you to explicitly specify the location - both the result and the multiplier. The third variant specifies the register, which will be the first factor and in which the multiplication result will be placed. The immediate operand means the indication of an undefined register, but the number by which the operand will be multiplied.

Division

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

DIV

For signed numbers use the command:

IDIV

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

Searching and determining places can be said the same as multiplication: you need a separate article, since the amount of information is very significant.

Useful conclusion

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

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

INC

For decrementation it is necessary to write:

DEC

A memory location or register can act as an operand. The exclusive benefit of these operations is that they take up less space for themselves than analogous assembler commands offered by adding or subtracting.

Similar articles

 

 

 

 

Trending Now

 

 

 

 

Newest

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