void bx_cpu_c::SUB_EbIb(BxInstruction_t *i) { Bit8u op2_8, op1_8, diff_8; op2_8 = i->Ib; /* op1_8 is a register or memory reference */ if (i->mod == 0xc0) { op1_8 = BX_READ_8BIT_REG(i->rm); } else { /* pointer, segment address pair */ read_RMW_virtual_byte(i->seg, i->rm_addr, &op1_8); } diff_8 = op1_8 - op2_8; /* now write diff back to destination */ if (i->mod == 0xc0) { BX_WRITE_8BIT_REG(i->rm, diff_8); } else { write_RMW_virtual_byte(diff_8); } SET_FLAGS_OSZAPC_8(op1_8, op2_8, diff_8, BX_INSTR_SUB8); }
void bx_cpu_c::DEC_Eb(BxInstruction_t *i) { Bit8u op1_8; /* op1_8 is a register or memory reference */ if (i->mod == 0xc0) { op1_8 = BX_READ_8BIT_REG(i->rm); } else { /* pointer, segment address pair */ read_RMW_virtual_byte(i->seg, i->rm_addr, &op1_8); } op1_8--; /* now write sum back to destination */ if (i->mod == 0xc0) { BX_WRITE_8BIT_REG(i->rm, op1_8); } else { write_RMW_virtual_byte(op1_8); } SET_FLAGS_OSZAP_8(0, 0, op1_8, BX_INSTR_DEC8); }
void bx_cpu_c::SBB_EbGb(BxInstruction_t *i) { Bit8u op2_8, op1_8, diff_8; Boolean temp_CF; temp_CF = get_CF(); /* op2 is a register, i->rm_addr is an index of a register */ op2_8 = BX_READ_8BIT_REG(i->nnn); /* op1_8 is a register or memory reference */ if (i->mod == 0xc0) { op1_8 = BX_READ_8BIT_REG(i->rm); } else { /* pointer, segment address pair */ read_RMW_virtual_byte(i->seg, i->rm_addr, &op1_8); } diff_8 = op1_8 - (op2_8 + temp_CF); /* now write diff back to destination */ if (i->mod == 0xc0) { BX_WRITE_8BIT_REG(i->rm, diff_8); } else { write_RMW_virtual_byte(diff_8); } SET_FLAGS_OSZAPC_8_CF(op1_8, op2_8, diff_8, BX_INSTR_SBB8, temp_CF); }
void bx_cpu_c::ADC_EbIb(BxInstruction_t *i) { Bit8u op2, op1, sum; Boolean temp_CF; temp_CF = get_CF(); op2 = i->Ib; /* op1 is a register or memory reference */ if (i->mod == 0xc0) { op1 = BX_READ_8BIT_REG(i->rm); } else { /* pointer, segment address pair */ read_RMW_virtual_byte(i->seg, i->rm_addr, &op1); } sum = op1 + op2 + temp_CF; /* now write sum back to destination */ if (i->mod == 0xc0) { BX_WRITE_8BIT_REG(i->rm, sum); } else { write_RMW_virtual_byte(sum); } SET_FLAGS_OSZAPC_8_CF(op1, op2, sum, BX_INSTR_ADC8, temp_CF); }
void bx_cpu_c::ADD_EbGb(BxInstruction_t *i) { Bit8u op2, op1, sum; /* op2 is a register, i->rm_addr is an index of a register */ op2 = BX_READ_8BIT_REG(i->nnn); /* op1 is a register or memory reference */ if (i->mod == 0xc0) { op1 = BX_READ_8BIT_REG(i->rm); } else { read_RMW_virtual_byte(i->seg, i->rm_addr, &op1); } sum = op1 + op2; /* now write sum back to destination */ if (i->mod == 0xc0) { BX_WRITE_8BIT_REG(i->rm, sum); } else { write_RMW_virtual_byte(sum); } SET_FLAGS_OSZAPC_8(op1, op2, sum, BX_INSTR_ADD8); }
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::DEC_EbM(bxInstruction_c *i) { bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i)); Bit32u op1_8 = read_RMW_virtual_byte(i->seg(), eaddr); op1_8--; write_RMW_virtual_byte(op1_8); SET_FLAGS_OSZAP_SUB_8(op1_8 + 1, 0, op1_8); BX_NEXT_INSTR(i); }
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::SBB_EbIbM(bxInstruction_c *i) { bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i)); Bit32u op1_8 = read_RMW_virtual_byte(i->seg(), eaddr); Bit32u op2_8 = i->Ib(); Bit32u diff_8 = op1_8 - (op2_8 + getB_CF()); write_RMW_virtual_byte(diff_8); SET_FLAGS_OSZAPC_SUB_8(op1_8, op2_8, diff_8); BX_NEXT_INSTR(i); }
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::ADC_EbGbM(bxInstruction_c *i) { bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i)); Bit32u op1 = read_RMW_virtual_byte(i->seg(), eaddr); Bit32u op2 = BX_READ_8BIT_REGx(i->nnn(), i->extend8bitL()); Bit32u sum = op1 + op2 + getB_CF(); write_RMW_virtual_byte(sum); SET_FLAGS_OSZAPC_ADD_8(op1, op2, sum); BX_NEXT_INSTR(i); }
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::ADD_EbIbM(bxInstruction_c *i) { bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i)); Bit32u op1 = read_RMW_virtual_byte(i->seg(), eaddr); Bit32u op2 = i->Ib(); Bit32u sum = op1 + op2; write_RMW_virtual_byte(sum); SET_FLAGS_OSZAPC_ADD_8(op1, op2, sum); BX_NEXT_INSTR(i); }
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::SUB_EbGbM(bxInstruction_c *i) { bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i)); Bit32u op1_8 = read_RMW_virtual_byte(i->seg(), eaddr); Bit32u op2_8 = BX_READ_8BIT_REGx(i->nnn(), i->extend8bitL()); Bit32u diff_8 = op1_8 - op2_8; write_RMW_virtual_byte(diff_8); SET_FLAGS_OSZAPC_SUB_8(op1_8, op2_8, diff_8); BX_NEXT_INSTR(i); }
void bx_cpu_c::XADD_EbGb(BxInstruction_t *i) { #if (BX_CPU_LEVEL >= 4) || (BX_CPU_LEVEL_HACKED >= 4) Bit8u op2, op1, sum; /* XADD dst(r/m8), src(r8) * temp <-- src + dst | sum = op2 + op1 * src <-- dst | op2 = op1 * dst <-- tmp | op1 = sum */ /* op2 is a register, i->rm_addr is an index of a register */ op2 = BX_READ_8BIT_REG(i->nnn); /* op1 is a register or memory reference */ if (i->mod == 0xc0) { op1 = BX_READ_8BIT_REG(i->rm); } else { /* pointer, segment address pair */ read_RMW_virtual_byte(i->seg, i->rm_addr, &op1); } sum = op1 + op2; /* now write sum back to destination */ if (i->mod == 0xc0) { // and write destination into source // Note: if both op1 & op2 are registers, the last one written // should be the sum, as op1 & op2 may be the same register. // For example: XADD AL, AL BX_WRITE_8BIT_REG(i->nnn, op1); BX_WRITE_8BIT_REG(i->rm, sum); } else { write_RMW_virtual_byte(sum); /* and write destination into source */ BX_WRITE_8BIT_REG(i->nnn, op1); } SET_FLAGS_OSZAPC_8(op1, op2, sum, BX_INSTR_XADD8); #else BX_PANIC(("XADD_EbGb: not supported on < 80486")); #endif }
void bx_cpu_c::CMPXCHG_EbGb(BxInstruction_t *i) { #if (BX_CPU_LEVEL >= 4) || (BX_CPU_LEVEL_HACKED >= 4) Bit8u op2_8, op1_8, diff_8; /* op1_8 is a register or memory reference */ if (i->mod == 0xc0) { op1_8 = BX_READ_8BIT_REG(i->rm); } else { /* pointer, segment address pair */ read_RMW_virtual_byte(i->seg, i->rm_addr, &op1_8); } diff_8 = AL - op1_8; SET_FLAGS_OSZAPC_8(AL, op1_8, diff_8, BX_INSTR_CMP8); if (diff_8 == 0) { // if accumulator == dest // ZF = 1 set_ZF(1); // dest <-- src op2_8 = BX_READ_8BIT_REG(i->nnn); if (i->mod == 0xc0) { BX_WRITE_8BIT_REG(i->rm, op2_8); } else { write_RMW_virtual_byte(op2_8); } } else { // ZF = 0 set_ZF(0); // accumulator <-- dest AL = op1_8; } #else BX_PANIC(("CMPXCHG_EbGb:")); #endif }
void BX_CPU_C::XCHG_EbGb(bxInstruction_c *i) { Bit8u op2, op1; op2 = BX_READ_8BIT_REGx(i->nnn(), i->extend8bitL()); /* op1 is a register or memory reference */ if (i->modC0()) { op1 = BX_READ_8BIT_REGx(i->rm(), i->extend8bitL()); BX_WRITE_8BIT_REGx(i->rm(), i->extend8bitL(), op2); } else { /* pointer, segment address pair */ read_RMW_virtual_byte(i->seg(), RMAddr(i), &op1); write_RMW_virtual_byte(op2); } BX_WRITE_8BIT_REGx(i->nnn(), i->extend8bitL(), op1); }
void bx_cpu_c::XCHG_EbGb(BxInstruction_t *i) { Bit8u op2, op1; /* op2 is a register, op2_addr is an index of a register */ op2 = BX_READ_8BIT_REG(i->nnn); /* op1 is a register or memory reference */ if (i->mod == 0xc0) { op1 = BX_READ_8BIT_REG(i->rm); BX_WRITE_8BIT_REG(i->rm, op2); } else { /* pointer, segment address pair */ read_RMW_virtual_byte(i->seg, i->rm_addr, &op1); write_RMW_virtual_byte(op2); } BX_WRITE_8BIT_REG(i->nnn, op1); }
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::CMPXCHG_EbGbM(bxInstruction_c *i) { bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i)); Bit32u op1_8 = read_RMW_virtual_byte(i->seg(), eaddr); Bit32u diff_8 = AL - op1_8; SET_FLAGS_OSZAPC_SUB_8(AL, op1_8, diff_8); if (diff_8 == 0) { // if accumulator == dest // dest <-- src Bit32u op2_8 = BX_READ_8BIT_REGx(i->nnn(), i->extend8bitL()); write_RMW_virtual_byte(op2_8); } else { // accumulator <-- dest AL = op1_8; } BX_NEXT_INSTR(i); }
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::XADD_EbGbM(bxInstruction_c *i) { /* XADD dst(r/m8), src(r8) * temp <-- src + dst | sum = op2 + op1 * src <-- dst | op2 = op1 * dst <-- tmp | op1 = sum */ bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i)); Bit32u op1 = read_RMW_virtual_byte(i->seg(), eaddr); Bit32u op2 = BX_READ_8BIT_REGx(i->nnn(), i->extend8bitL()); Bit32u sum = op1 + op2; write_RMW_virtual_byte(sum); /* and write destination into source */ BX_WRITE_8BIT_REGx(i->nnn(), i->extend8bitL(), op1); SET_FLAGS_OSZAPC_ADD_8(op1, op2, sum); BX_NEXT_INSTR(i); }