Compilation Summary: Unsigned division, signed division, remainder, unsigned multiplication, symbolic multiplication

Source: Internet
Author: User

This article is divided into 3 modules.

    1. Example---example of this directive

    2. explain ---to the point where the instructions are difficult to understand

    3. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.