1. IDIV crash

I was coding some fixed-math routines in assembly using asm.e when I
noticed this problem: IDIV crashes the program when dividing with
anything else than the lower byte of a register. This means that I
couldn't use:

MOV EAX,some_number
MOV EBX,another_number
IDIV EBX

Instead I had to use:

MOV EAX,some_number
MOV EBX,another_number
IDIV BL

And values up to 256 are not enough when using fixed-point math.
I tried the same thing in TASM and it wouldn't work there either, I got
the message "division error" when I ran the .exe file.
Does this have something to do with my processor (a P2), or is it just a
fact that you can't divide a 32-bit number with another 32-bit number ?
(seems unlikely to me)



______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com

new topic     » topic index » view message » categorize

2. Re: IDIV crash

On Sun, 7 Mar 1999, stab master wrote:

> I was coding some fixed-math routines in assembly using asm.e when I
> noticed this problem: IDIV crashes the program when dividing with
> anything else than the lower byte of a register. This means that I
> couldn't use:

That's because IDIV actually does EDX:EAX / EBX for the following code:
(EDX and EAX combine for a 64-bit value)

> MOV EAX,some_number
> MOV EBX,another_number
> IDIV EBX

If EDX is too large when EBX is small, the result of the division will not
fit in EAX and the IDIV will bomb with a divide-by-zero error.  What you
probably want to do is just set EDX to zero before the division.

> Instead I had to use:
>
> MOV EAX,some_number
> MOV EBX,another_number
> IDIV BL

This just does AL = AX / BL

> And values up to 256 are not enough when using fixed-point math.
> I tried the same thing in TASM and it wouldn't work there either, I got
> the message "division error" when I ran the .exe file.
> Does this have something to do with my processor (a P2), or is it just a
> fact that you can't divide a 32-bit number with another 32-bit number ?
> (seems unlikely to me)

Nothing wrong with your processor... just another quirk to learn in
assembly programming.

--
Pete <xseal at harborside.com>
http://www.harborside.com/home/x/xseal/euphoria/

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu