flat assembler
Message board for the users of flat assembler.
Index
> Main > Integer Division |
Author |
|
DimonSoft 10 Mar 2018, 19:06
CandyMan wrote: how to check whether the quotient will fit in AL before integer division (TheWord>0xFF)? You’d better perform division for double-sized values. Code: mov ax, [TheWord] cwd movsx cx, cl idiv cx You’re not in control of #DE anyway and wouldn’t like to be. So just prevent it. |
|||
10 Mar 2018, 19:06 |
|
CandyMan 10 Mar 2018, 20:39
Thanks. This works with byte integer division. How to prevent exception in this case:
Code: mov edx,[Hi] mov eax,[Lo] idiv ecx _________________ smaller is better |
|||
10 Mar 2018, 20:39 |
|
Tomasz Grysztar 10 Mar 2018, 21:38
You may already be aware that for unsigned division this is very simple:
Code: mov edx,[Hi] mov eax,[Lo] cmp edx,ecx jae overflow div ecx The signed case is much more complex. You need EDX:EAX to be larger than -(1 shl 31 + 1)*ECX and smaller than (1 shl 31)*ECX, this could be tested with some shifts, but would not be as nice and simple. |
|||
10 Mar 2018, 21:38 |
|
CandyMan 11 Mar 2018, 12:33
I am thanking everyone for help.
|
|||
11 Mar 2018, 12:33 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.