mirror of
https://github.com/reactos/reactos.git
synced 2025-05-29 05:58:13 +00:00
[SOFTX86]
Fix carry/overflow flag computation for ADD instructions. svn path=/branches/ntvdm/; revision=59725
This commit is contained in:
parent
e387f7f1cd
commit
a88f650367
1 changed files with 31 additions and 21 deletions
52
lib/3rdparty/softx86/softx86/add.c
vendored
52
lib/3rdparty/softx86/softx86/add.c
vendored
|
@ -35,13 +35,16 @@ sx86_ubyte op_add8(softx86_ctx* ctx,sx86_ubyte src,sx86_ubyte val)
|
||||||
/* peform the addition */
|
/* peform the addition */
|
||||||
ret = src + val;
|
ret = src + val;
|
||||||
|
|
||||||
/* if carry/overflow */
|
/* if carry */
|
||||||
if (ret < src)
|
if ((ret < src) || (ret < val)) ctx->state->reg_flags.val |= SX86_CPUFLAG_CARRY;
|
||||||
ctx->state->reg_flags.val |=
|
else ctx->state->reg_flags.val &= ~SX86_CPUFLAG_CARRY;
|
||||||
(SX86_CPUFLAG_CARRY | SX86_CPUFLAG_OVERFLOW);
|
|
||||||
else
|
/* if overflow */
|
||||||
ctx->state->reg_flags.val &=
|
if (((src & 0x80) == (val & 0x80)) && ((src & 0x80) != (ret & 0x80)))
|
||||||
~(SX86_CPUFLAG_CARRY | SX86_CPUFLAG_OVERFLOW);
|
{
|
||||||
|
ctx->state->reg_flags.val |= SX86_CPUFLAG_OVERFLOW;
|
||||||
|
}
|
||||||
|
else ctx->state->reg_flags.val &= ~SX86_CPUFLAG_OVERFLOW;
|
||||||
|
|
||||||
/* if result treated as signed value is negative */
|
/* if result treated as signed value is negative */
|
||||||
if (ret & 0x80) ctx->state->reg_flags.val |= SX86_CPUFLAG_SIGN;
|
if (ret & 0x80) ctx->state->reg_flags.val |= SX86_CPUFLAG_SIGN;
|
||||||
|
@ -79,13 +82,16 @@ sx86_uword op_add16(softx86_ctx* ctx,sx86_uword src,sx86_uword val)
|
||||||
/* peform the addition */
|
/* peform the addition */
|
||||||
ret = src + val;
|
ret = src + val;
|
||||||
|
|
||||||
/* if carry/overflow */
|
/* if carry */
|
||||||
if (ret < src)
|
if ((ret < src) || (ret < val)) ctx->state->reg_flags.val |= SX86_CPUFLAG_CARRY;
|
||||||
ctx->state->reg_flags.val |=
|
else ctx->state->reg_flags.val &= ~SX86_CPUFLAG_CARRY;
|
||||||
(SX86_CPUFLAG_CARRY | SX86_CPUFLAG_OVERFLOW);
|
|
||||||
else
|
/* if overflow */
|
||||||
ctx->state->reg_flags.val &=
|
if (((src & 0x8000) == (val & 0x8000)) && ((src & 0x8000) != (ret & 0x8000)))
|
||||||
~(SX86_CPUFLAG_CARRY | SX86_CPUFLAG_OVERFLOW);
|
{
|
||||||
|
ctx->state->reg_flags.val |= SX86_CPUFLAG_OVERFLOW;
|
||||||
|
}
|
||||||
|
else ctx->state->reg_flags.val &= ~SX86_CPUFLAG_OVERFLOW;
|
||||||
|
|
||||||
/* if result treated as signed value is negative */
|
/* if result treated as signed value is negative */
|
||||||
if (ret & 0x8000)
|
if (ret & 0x8000)
|
||||||
|
@ -125,13 +131,17 @@ sx86_udword op_add32(softx86_ctx* ctx,sx86_udword src,sx86_udword val)
|
||||||
/* peform the addition */
|
/* peform the addition */
|
||||||
ret = src + val;
|
ret = src + val;
|
||||||
|
|
||||||
/* if carry/overflow */
|
/* if carry */
|
||||||
if (ret < src)
|
if ((ret < src) || (ret < val)) ctx->state->reg_flags.val |= SX86_CPUFLAG_CARRY;
|
||||||
ctx->state->reg_flags.val |=
|
else ctx->state->reg_flags.val &= ~SX86_CPUFLAG_CARRY;
|
||||||
(SX86_CPUFLAG_CARRY | SX86_CPUFLAG_OVERFLOW);
|
|
||||||
else
|
/* if overflow */
|
||||||
ctx->state->reg_flags.val &=
|
if (((src & 0x80000000) == (val & 0x80000000))
|
||||||
~(SX86_CPUFLAG_CARRY | SX86_CPUFLAG_OVERFLOW);
|
&& ((src & 0x80000000) != (ret & 0x80000000)))
|
||||||
|
{
|
||||||
|
ctx->state->reg_flags.val |= SX86_CPUFLAG_OVERFLOW;
|
||||||
|
}
|
||||||
|
else ctx->state->reg_flags.val &= ~SX86_CPUFLAG_OVERFLOW;
|
||||||
|
|
||||||
/* if result treated as signed value is negative */
|
/* if result treated as signed value is negative */
|
||||||
if (ret & 0x80000000)
|
if (ret & 0x80000000)
|
||||||
|
|
Loading…
Reference in a new issue