flat assembler
Message board for the users of flat assembler.
Index
> Windows > DIV Command |
Author |
|
LocoDelAssembly 20 Oct 2007, 04:19
Because it actually performs:
EAX = EDX:EAX div divisor (1) {[(EDX * 4294967296 + EAX) / divisor]} EDX = EDX:EAX mod divisor (2) {(EDX * 4294967296 + EAX) mod divisor} (with div and mod behaving like in Pascal language) Since (2) is impossible to give a value greater or equal to the divisor that part never overflows. However, we can't say the same about (1), by just having EDX=1 and EAX=0, dividing by 1 is enough to overflow because EDX:EAX before division is 4294967296, and after division is the same value again, but the maximun value supported in EAX (a 32-bit reg), is 4294967295 (one minus than the result). To sumarize, you will get overflows if the divisor of EDX:EAX cannot reduce the number to a value less than 4294967296. You'll typically want to clear EDX before dividing using XOR EDX, EDX; MOV EDX, 0; or any other thing that you found more suitable for your particular context. |
|||
20 Oct 2007, 04:19 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.