#include "setcc.h" #include "codes.h" #include #include #include using namespace std::string_literals; namespace { struct Operation { std::string name; OP_T opcode; }; std::vector setccOps { {"seta", OP_T{ 0x0F, 0x97 }}, {"setae", OP_T{ 0x0F, 0x93 }}, {"setb", OP_T{ 0x0F, 0x92 }}, {"setbe", OP_T{ 0x0F, 0x96 }}, {"setc", OP_T{ 0x0F, 0x92 }}, {"sete", OP_T{ 0x0F, 0x94 }}, {"setg", OP_T{ 0x0F, 0x9F }}, {"setge", OP_T{ 0x0F, 0x9D }}, {"setl", OP_T{ 0x0F, 0x9C }}, {"setle", OP_T{ 0x0F, 0x9E }}, {"setna", OP_T{ 0x0F, 0x96 }}, {"setnae",OP_T{ 0x0F, 0x92 }}, {"setnb", OP_T{ 0x0F, 0x93 }}, {"setnbe",OP_T{ 0x0F, 0x97 }}, {"setnc", OP_T{ 0x0F, 0x93 }}, {"setne", OP_T{ 0x0F, 0x95 }}, {"setng", OP_T{ 0x0F, 0x9E }}, {"setnge",OP_T{ 0x0F, 0x9C }}, {"setnl", OP_T{ 0x0F, 0x9D }}, {"setnle",OP_T{ 0x0F, 0x9F }}, {"setno", OP_T{ 0x0F, 0x91 }}, {"setnp", OP_T{ 0x0F, 0x9B }}, {"setns", OP_T{ 0x0F, 0x99 }}, {"setnz", OP_T{ 0x0F, 0x95 }}, {"seto", OP_T{ 0x0F, 0x90 }}, {"setp", OP_T{ 0x0F, 0x9A }}, {"setpe", OP_T{ 0x0F, 0x9A }}, {"setpo", OP_T{ 0x0F, 0x9B }}, {"sets", OP_T{ 0x0F, 0x98 }}, {"setz", OP_T{ 0x0F, 0x94 }}, }; bool registerOps() { bool result{true}; for (const auto& setccOp: setccOps) { result &= registerOp(mangleName(setccOp.name), [&](const Asm::Args& args) -> std::shared_ptr{ return std::make_shared(setccOp.name, args, setccOp.opcode); }); result &= registerOp(mangleName(setccOp.name), [&](const Asm::Args& args) -> std::shared_ptr{ return std::make_shared(setccOp.name, args, setccOp.opcode); }); } return result; } bool registered { registerOps() }; } Op_setcc::Op_setcc(const std::string& name, const Asm::Args& args, const OP_T& opcode) { if (args[0].type() == typeid(Asm::Args::Register8)) { // setcc reg8 // actually, reg field of ModRM is ignored and could be different from /0 machine_code = opcode + ModRM("/0", std::any_cast(args[0]).name()); } else if (args[0].type() == typeid(Asm::Args::Mem8Ptr64)) { // setcc byte ptr [reg64] Asm::Args::Mem8Ptr64 ptr{std::any_cast(args[0])}; // actually, reg field of ModRM is ignored and could be different from /0 machine_code = opcode + ModRM("/0", ptr.reg(), ptr.offs()); } else { throw std::runtime_error("Unimplemented: setcc "s + args[0].type().name() + " "s + args[1].type().name()); } }