About the use of assembly DIV/IDIV/MUL/IMUL instructions

Source: Internet
Author: User
Tags mul
You may be deeply aware that when using the DIV/IDIV directive, running the program often inexplicably pop-up "the program to perform illegal operation" error, usually "division overflow", but your code may be as follows:
MOV eax,1000
Cwd
Div CX
Generally after using the CWD command, it can be normal, but very unstable, I feel strange, why this?
Huitiansou's Answer:
Yes: "About the use of Div/idiv/mul/imul directives by AoGo" causes a bug
That's because the divisor reached the double value,
So it can't be extended with symbols,
and can only send a high of 16 digits 0
All we have to do is make sure that edx is 0, and that this method is recommended when running 32-digit division, and absolutely not illegal operations (except for 0/overflow, of course).
Example:
XOR Edx,edx
MOV eax,6527363
MOV ecx,28732
div ECX
All you have to do is remove the above XOR Edx,edx command to ensure 100% illegal operation.
Also, multiplication instructions can do this. can be guaranteed to be more secure.

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.