This article is divided into 3 modules.
Example---example of this directive
explain ---to the point where the instructions are difficult to understand
Practice ---in order to become more familiar with the directive
1.1 Signed Division instruction and take-over example:
In the C language to complete the 8/2 assembly instructions are as follows:
in C language to complete 8 2 of the assembly instructions are as follows:
An example of a 4-byte division and take-rest operation is as follows:
. section. Text.global _start_start:movl $8,%eax #被除数是%edx:%eax are these two registers together%eax store low%edx storage high movl%eax,%edx sh RL $31,%edx #根据符号位填充%edx Register MOVL $,%ECX IDIVL%ecx #%eax depositary%edx Save remainder
Different types are used (C has a similar concept) and has the following variants:
An example of a 1-byte division and take-rest operation is as follows:
. section. Text.global _start_start:movw $8,%ax #被除数是%ax register Movb,%cl IDIVB%cl #除数可以是通用寄存器, the demo here is%CL. %al the storage provider. %ah storing remainder
An example of a 2-byte division and take-rest operation is as follows:
. section. Text.global _start_start:movw $8,%ax #被除数是%dx:%ax are these two registers together%ax store low%DX storage high MOVW%ax,%dx SHRW %dx MOVW,%CX idivw%cx #%ax depositary%dx Save remainder
An example of a 8-byte division and take-rest operation is as follows:
. section. Text.global _start_start:movq $8,%rax #被除数是%rdx:%rax are these two registers together%rax store low%RDX storage high movq%rax,%RDX shr Q $63,%rdx movq,%RCX idivq%RCX #%rax depositary%rdx Save remainder
1.2 Why do I use the right shift command in the divisor instruction%edx
. section. Text.global _start_start:movl $8,%eax #1 movl%eax,%edx #2 shrl $31,%edx #3 movl $,%ECX # 4 IDIVL%ecx #5
In the above example, line 2+3 actually sets the%edx to full 0 or all according to the symbols in the dividend%eax. In this way, two registers are spelled into 64-bit registers (%edx:%eax--)
1.3 unsigned divisor
The unsigned divisor and the signed divisor are about the same, just change the idiv to Div.
2.1 Signed Multiplication Instruction example:
In C language to complete 4 3 of the assembly instructions are as follows:
Different types are used (C language has similar concepts) and the following variants:
2.2
3.1 Write a function that implements a string to a number. The function prototypes are as follows:
int str2int (const char *STR, int base);
The base range is 2-36, and the array in STR can be interpreted as a number of 2-36 binary
Need to provide a certain amount of input guessing ability. When base is 0 o'clock, the binary guessing capability is turned on. STR starts with 0b or 0 B, and defaults to 2 binary. Starting with 0 defaults to 8 binary. Starting with 0x or 0X, the default is 16, and the rest defaults to 10 binary.
STR begins with '-'. Base is 10 o'clock, which is considered a negative number of 10 binary. The rest of the binary?
Assembly Code:
3.2 Write the function, implement the number to the string, the function prototype is as follows:
Char *int2str (int val, char *str, int base);
The base range is 2-36, which interprets the number in Val as a 2-36-binary string and is stored in Str.
Val is the input. STR is the output.
Assembly Code:
Compilation Summary: Unsigned division, signed division, remainder, unsigned multiplication, symbolic multiplication