summaryrefslogtreecommitdiffhomepage
path: root/asm/intel64/setcc.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'asm/intel64/setcc.cpp')
-rw-r--r--asm/intel64/setcc.cpp84
1 files changed, 84 insertions, 0 deletions
diff --git a/asm/intel64/setcc.cpp b/asm/intel64/setcc.cpp
new file mode 100644
index 0000000..aa7219f
--- /dev/null
+++ b/asm/intel64/setcc.cpp
@@ -0,0 +1,84 @@
+#include "setcc.h"
+
+#include "codes.h"
+
+#include <asm/assembler.h>
+#include <asm/operators.h>
+
+#include <asm/intel64/codes.h>
+
+using namespace std::string_literals;
+
+namespace {
+ struct Operation {
+ std::string name;
+ OP_T opcode;
+ };
+
+ std::vector<Operation> 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<Asm::Args::Register8>(setccOp.name), [&](const Asm::Args& args) -> std::shared_ptr<Op>{
+ return std::make_shared<Op_setcc>(setccOp.name, args, setccOp.opcode);
+ });
+ result &= registerOp(mangleName<Asm::Args::Mem8Ptr64>(setccOp.name), [&](const Asm::Args& args) -> std::shared_ptr<Op>{
+ return std::make_shared<Op_setcc>(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<Asm::Args::Register8>(args[0]).name());
+
+ } else if (args[0].type() == typeid(Asm::Args::Mem8Ptr64)) { // setcc byte ptr [reg64]
+ Asm::Args::Mem8Ptr64 ptr{std::any_cast<Asm::Args::Mem8Ptr64>(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());
+ }
+}
+