mirror of
https://github.com/reactos/reactos.git
synced 2025-01-01 03:54:02 +00:00
[SOFTX86]
Fix carry/overflow condition for the SUB instruction. svn path=/branches/ntvdm/; revision=59490
This commit is contained in:
parent
40d639e7ff
commit
f82876686a
1 changed files with 25 additions and 15 deletions
40
lib/3rdparty/softx86/softx86/add.c
vendored
40
lib/3rdparty/softx86/softx86/add.c
vendored
|
@ -342,13 +342,16 @@ sx86_ubyte op_sub8(softx86_ctx* ctx,sx86_ubyte src,sx86_ubyte val)
|
|||
/* peform the addition */
|
||||
ret = src - val;
|
||||
|
||||
/* if carry/overflow */
|
||||
if (ret > src)
|
||||
ctx->state->reg_flags.val |=
|
||||
(SX86_CPUFLAG_CARRY | SX86_CPUFLAG_OVERFLOW);
|
||||
else
|
||||
ctx->state->reg_flags.val &=
|
||||
~(SX86_CPUFLAG_CARRY | SX86_CPUFLAG_OVERFLOW);
|
||||
/* if carry */
|
||||
if (val > src) ctx->state->reg_flags.val |= SX86_CPUFLAG_CARRY;
|
||||
else ctx->state->reg_flags.val &= ~SX86_CPUFLAG_CARRY;
|
||||
|
||||
/* if overflow */
|
||||
if (((src & 0x80) != (val & 0x80)) && ((src & 0x80) != (ret & 0x80)))
|
||||
{
|
||||
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 (ret & 0x80) ctx->state->reg_flags.val |= SX86_CPUFLAG_SIGN;
|
||||
|
@ -391,7 +394,10 @@ sx86_uword op_sub16(softx86_ctx* ctx,sx86_uword src,sx86_uword val)
|
|||
else ctx->state->reg_flags.val &= ~SX86_CPUFLAG_CARRY;
|
||||
|
||||
/* if overflow */
|
||||
if ((ret & 0x8000) != (src & 0x8000)) ctx->state->reg_flags.val |= SX86_CPUFLAG_OVERFLOW;
|
||||
if (((src & 0x8000) != (val & 0x8000)) && ((src & 0x8000) != (ret & 0x8000)))
|
||||
{
|
||||
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 */
|
||||
|
@ -430,13 +436,17 @@ sx86_udword op_sub32(softx86_ctx* ctx,sx86_udword src,sx86_udword val)
|
|||
/* peform the addition */
|
||||
ret = src - val;
|
||||
|
||||
/* if carry/overflow */
|
||||
if (ret > src)
|
||||
ctx->state->reg_flags.val |=
|
||||
(SX86_CPUFLAG_CARRY | SX86_CPUFLAG_OVERFLOW);
|
||||
else
|
||||
ctx->state->reg_flags.val &=
|
||||
~(SX86_CPUFLAG_CARRY | SX86_CPUFLAG_OVERFLOW);
|
||||
/* if carry */
|
||||
if (val > src) ctx->state->reg_flags.val |= SX86_CPUFLAG_CARRY;
|
||||
else ctx->state->reg_flags.val &= ~SX86_CPUFLAG_CARRY;
|
||||
|
||||
/* if overflow */
|
||||
if (((src & 0x80000000) != (val & 0x80000000))
|
||||
&& ((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 (ret & 0x80000000) ctx->state->reg_flags.val |= SX86_CPUFLAG_SIGN;
|
||||
|
|
Loading…
Reference in a new issue