mirror of
https://github.com/TomHarte/CLK.git
synced 2025-02-16 18:30:32 +00:00
Unify AAA and AAS.
This commit is contained in:
parent
8d2a2bcf4a
commit
5f1ea6c04c
@ -15,67 +15,21 @@
|
||||
|
||||
namespace InstructionSet::x86::Primitive {
|
||||
|
||||
template <typename ContextT>
|
||||
void aaa(
|
||||
CPU::RegisterPair16 &ax,
|
||||
ContextT &context
|
||||
) { // P. 313
|
||||
/*
|
||||
IF ((AL AND 0FH) > 9) OR (AF = 1)
|
||||
THEN
|
||||
AL ← (AL + 6);
|
||||
AH ← AH + 1;
|
||||
AF ← 1;
|
||||
CF ← 1;
|
||||
ELSE
|
||||
AF ← 0;
|
||||
CF ← 0;
|
||||
FI;
|
||||
AL ← AL AND 0FH;
|
||||
*/
|
||||
/*
|
||||
The AF and CF flags are set to 1 if the adjustment results in a decimal carry;
|
||||
otherwise they are cleared to 0. The OF, SF, ZF, and PF flags are undefined.
|
||||
*/
|
||||
if((ax.halves.low & 0x0f) > 9 || context.flags.template flag<Flag::AuxiliaryCarry>()) {
|
||||
ax.halves.low += 6;
|
||||
++ax.halves.high;
|
||||
context.flags.template set_from<Flag::Carry, Flag::AuxiliaryCarry>(1);
|
||||
} else {
|
||||
context.flags.template set_from<Flag::Carry, Flag::AuxiliaryCarry>(0);
|
||||
}
|
||||
ax.halves.low &= 0x0f;
|
||||
}
|
||||
|
||||
|
||||
template <typename ContextT>
|
||||
void aas(
|
||||
/// If @c add is @c true, performs an AAA; otherwise perfoms an AAS.
|
||||
template <bool add, typename ContextT>
|
||||
void aaas(
|
||||
CPU::RegisterPair16 &ax,
|
||||
ContextT &context
|
||||
) {
|
||||
/*
|
||||
IF ((AL AND 0FH) > 9) OR (AF = 1)
|
||||
THEN
|
||||
AL ← AL – 6;
|
||||
AH ← AH – 1;
|
||||
AF ← 1;
|
||||
CF ← 1;
|
||||
ELSE
|
||||
CF ← 0;
|
||||
AF ← 0;
|
||||
FI;
|
||||
AL ← AL AND 0FH;
|
||||
*/
|
||||
/*
|
||||
The AF and CF flags are set to 1 if there is a decimal borrow;
|
||||
otherwise, they are cleared to 0. The OF, SF, ZF, and PF flags are undefined.
|
||||
*/
|
||||
if((ax.halves.low & 0x0f) > 9 || context.flags.template flag<Flag::AuxiliaryCarry>()) {
|
||||
ax.halves.low -= 6;
|
||||
--ax.halves.high;
|
||||
if constexpr (add) {
|
||||
ax.halves.low += 6;
|
||||
++ax.halves.high;
|
||||
} else {
|
||||
ax.halves.low -= 6;
|
||||
--ax.halves.high;
|
||||
}
|
||||
context.flags.template set_from<Flag::Carry, Flag::AuxiliaryCarry>(1);
|
||||
} else {
|
||||
context.flags.template set_from<Flag::Carry, Flag::AuxiliaryCarry>(0);
|
||||
}
|
||||
ax.halves.low &= 0x0f;
|
||||
}
|
||||
|
@ -175,10 +175,10 @@ template <
|
||||
case Operation::ESC:
|
||||
case Operation::NOP: return;
|
||||
|
||||
case Operation::AAA: Primitive::aaa(context.registers.axp(), context); return;
|
||||
case Operation::AAD: Primitive::aad(context.registers.axp(), instruction.operand(), context); return;
|
||||
case Operation::AAM: Primitive::aam(context.registers.axp(), instruction.operand(), context); return;
|
||||
case Operation::AAS: Primitive::aas(context.registers.axp(), context); return;
|
||||
case Operation::AAD: Primitive::aad(context.registers.axp(), instruction.operand(), context); return;
|
||||
case Operation::AAA: Primitive::aaas<true>(context.registers.axp(), context); return;
|
||||
case Operation::AAS: Primitive::aaas<false>(context.registers.axp(), context); return;
|
||||
case Operation::DAA: Primitive::daas<true>(context.registers.al(), context); return;
|
||||
case Operation::DAS: Primitive::daas<false>(context.registers.al(), context); return;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user