Hi Guys,

In the Win32 beta version of Randall Hydes's AOA (Volume 2: Questions, Projects and Laboratory Exercises), there's this question that I can't find the answer to:

------------------------------------------------------------------------------------------------------------
50. How can you check for unsigned arithmetic overflow immediately after an ?INC( EAX );? instruction?
------------------------------------------------------------------------------------------------------------

I have read that the INC instruction does not update the FLAGS register, and I've tried searching through everything in Volume 1 & 2 in the book but I can't find the answer.

Could someone be so kind as to give me, at least, a reference to a source where I may find out how to get the result of an INC instruction.

Thanks Guys.
Posted on 2003-06-19 07:50:04 by Jaysen
I just pasted it from MASM32 Help Opcodes.

INC:

Modifies flags: AF OF PF SF ZF


I hope it's the same "INC"
Posted on 2003-06-19 09:07:16 by AceEmbler

Hi Guys,


I have read that the INC instruction does not update the FLAGS register, and I've tried searching through everything in Volume 1 & 2 in the book but I can't find the answer.

Could someone be so kind as to give me, at least, a reference to a source where I may find out how to get the result of an INC instruction.

Thanks Guys.


INC doesn't affect the carry flags, but it does affect the zero, overflow, and sign flags. The only time overflow occurs when incrementing an unsigned value is when you increment from $FF, $FFFF, or $FFFF_FFFF to zero. And this operation just happens to set the zero flag.
Cheers,
Randy Hyde
Posted on 2003-06-19 17:15:13 by rhyde
If eax overflows from an increment, then the result will be zero if you are incrementing by one. If you are incrementing by more than one, then the value will naturally be > 0.

You could compare the value of eax before the increment and after the increment. If eax(after) < eax(before), then this means there must have been overflow. I don't think this is as efficient as checking the zero flag, but it does allow you to check for overflow without looking at the flags.

I think.
Posted on 2003-06-19 21:20:53 by CaptainKirk
Many thanks AceEmbler, *THE* Randall Hyde, and last (but not least) CaptainKirk.
Posted on 2003-06-20 03:39:00 by Jaysen