From 387af55e498970975d77291374e2f5be12a040bd Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Fri, 13 Nov 2020 09:34:45 +0100 Subject: Added intel sub, div, idiv --- asm/intel64/sub.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 asm/intel64/sub.cpp (limited to 'asm/intel64/sub.cpp') diff --git a/asm/intel64/sub.cpp b/asm/intel64/sub.cpp new file mode 100644 index 0000000..e055ee9 --- /dev/null +++ b/asm/intel64/sub.cpp @@ -0,0 +1,42 @@ +#include "sub.h" + +#include "codes.h" + +#include +#include + +using namespace std::string_literals; + +Op_sub::Op_sub(Asm::Args& args) +{ + if (args[0].type() == typeid(Asm::Args::Register32) && + std::any_cast(args[0]).name() == "eax" && + args[1].type() == typeid(Asm::Args::Immediate32)) + { // sub eax, imm32 (before "sub reg32, imm32"! It's shorter.) + machine_code = std::vector{ 0x2D } + std::any_cast(args[1]).getCode(); + } else if (args[0].type() == typeid(Asm::Args::Register32) && + args[1].type() == typeid(Asm::Args::Immediate32)) + { // sub reg32, imm32 + machine_code = std::vector{ 0x81 } + ModRM("/5", std::any_cast(args[0]).name()) + std::any_cast(args[1]).getCode(); + } else if (args[0].type() == typeid(Asm::Args::Register64) && + std::any_cast(args[0]).name() == "rax" && + args[1].type() == typeid(Asm::Args::Immediate32)) + { // sub reg, imm32 + machine_code = REX("W") + machine_code = std::vector{ 0x81 } + ModRM("/5", std::any_cast(args[0]).name()) + std::any_cast(args[1]).getCode(); + } else { + throw std::runtime_error("Unimplemented: sub "s + args[0].type().name() + " "s + args[1].type().name()); + } +} + +namespace { + +bool registered { + registerOp(mangleName("sub"), [](Asm::Args& args) -> std::shared_ptr{ + return std::make_shared(args); + }) && + registerOp(mangleName("sub"), [](Asm::Args& args) -> std::shared_ptr{ + return std::make_shared(args); + }) +}; + +} -- cgit v1.2.3