本文整理汇总了C++中CPU::regs方法的典型用法代码示例。如果您正苦于以下问题:C++ CPU::regs方法的具体用法?C++ CPU::regs怎么用?C++ CPU::regs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CPU
的用法示例。
在下文中一共展示了CPU::regs方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AAA
AAA() : GenericInstruction(1, "aad", [](Machine& machine) {
CPU* cpu = machine.cpu;
Registers& regs = cpu->regs();
if ((regs.al() & 0x0F) > 9 || regs.flags().AF)
{
regs.ax() += 0x106;
regs.flags().AF = 1;
regs.flags().CF = 1;
}
else
{
regs.flags().AF = 0;
regs.flags().CF = 0;
}
regs.al() &= 0x0F;
})
{ }
示例2: if
std::unique_ptr<Instruction> Decoder::decode(Machine& machine)
{
CPU* cpu = machine.cpu;
Mode operandMode = cpu->getMode(), addressMode = cpu->getMode();
u32 startAddress = cpu->regs().eip();
u8 opcode = cpu->fetch<u8>();
Instruction* i = nullptr;
// operand size prefix
if (opcode == OP_PREFIX_OPERAND)
{
operandMode = operandMode == Mode::BITS16 ? Mode::BITS32 : Mode::BITS16;
opcode = cpu->fetch<u8>();
}
if (opcode == OP_PREFIX_ADDRESS)
{
addressMode = addressMode == Mode::BITS16 ? Mode::BITS32 : Mode::BITS16;
opcode = cpu->fetch<u8>();
}
// mov r8, imm8
if ((opcode & ~OP_REG_MASK) == OP_MOV_IMM8)
{
u8 imm = machine.cpu->fetch<u8>();
i = new MovImmediateR<reg8>(machine, opcode, imm);
}
// mov r16/32, imm16/32
else if ((opcode & ~OP_REG_MASK) == OP_MOV_IMM1632)
{
if (operandMode == Mode::BITS16)
{
u16 imm = machine.cpu->fetch<u16>();
i = new MovImmediateR<reg16>(machine, opcode, imm);
}
else
{
u32 imm = machine.cpu->fetch<u32>();
i = new MovImmediateR<reg32>(machine, opcode, imm);
}
}
// mov r8/16/32, rm8/16/32
// mov rm8/16/32, r8/16/32
else if ((opcode & ~OP_RM_MASK) == OP_MOV_REG_RM)
{
bool is8bit = !(opcode & OP_WIDTH_BIT);
u8 rmByte = cpu->fetch<u8>();
RMInstructionBase* ii = nullptr;
if (is8bit)
{
if (addressMode == Mode::BITS16)
ii = new MovRegRM<reg8, reg16>(opcode,rmByte);
else
ii = new MovRegRM<reg8, reg32>(opcode, rmByte);
}
else
{
if (addressMode == Mode::BITS16)
ii = operandMode == Mode::BITS16 ? (RMInstructionBase*)new MovRegRM<reg16, reg16>(opcode,rmByte) : new MovRegRM<reg32, reg16>(opcode,rmByte);
else if (addressMode == Mode::BITS32)
{
ii = operandMode == Mode::BITS16 ? (RMInstructionBase*)new MovRegRM<reg16, reg32>(opcode,rmByte) : new MovRegRM<reg32, reg32>(opcode,rmByte);
if (ii->hasSibByte())
ii->setSIBByte(cpu->fetch<u8>());
}
}
ii->fetchDisplacement(machine);
i = ii;
}
// AAA
else if (opcode == OP_AAA) { i = new AAA(); }
// NOP
else if (opcode == OP_NOP) { i = new NOP(); }
if (i) i->setStartingAddress(startAddress);
return unique_ptr<Instruction>(i);
};