Computers, Programming
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.
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
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
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