Re: DIV overflow




Hello Brian,

[...]

so is the sign extension necessary with unsigned division? Also, in
the above, you say "sign extension" but have "MOVZX"... you meant
"MOVSX", right?

No, sorry for the confusion.

Unsigned DIV:

MOVZX ebx, word divisor ;if you want a "16-bit Unsigned" divisor
MOV eax, dword dividend
XOR edx,edx ;edx=0
DIV ebx ;cannot overflow

Signed DIV:

MOVSX ebx, word divisor ;if you want a "16-bit Signed" divisor
MOV eax, dword dividend
CDQ ;edx= 0 or -1 depending on MSbit of eax
IDIV ebx ;cannot overflow


You can also use MOV ebx, dword divisor in both instead of MOVSx/Zx
IF "you want a 32 bit divisor".

__
wolfgang





.