summaryrefslogtreecommitdiffhomepage
path: root/asm/assembler.cpp
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2020-11-22 13:00:06 +0100
committerRoland Reichwein <mail@reichwein.it>2020-11-22 13:00:06 +0100
commit1fae63de23320a1663b7c591e247ad81852ab6dc (patch)
treebfe539b7eeb5a4d7b68aa1bf853898d60e34f784 /asm/assembler.cpp
parent739297d8895b08a9ecd8e81b01b7ba8e8dc4a8ae (diff)
Support 16-bit short
Diffstat (limited to 'asm/assembler.cpp')
-rw-r--r--asm/assembler.cpp182
1 files changed, 167 insertions, 15 deletions
diff --git a/asm/assembler.cpp b/asm/assembler.cpp
index 35e971b..88481bc 100644
--- a/asm/assembler.cpp
+++ b/asm/assembler.cpp
@@ -1,7 +1,38 @@
#include "assembler.h"
+#include "byteorder.h"
+
using namespace std::string_literals;
+Asm::Args::Immediate8::Immediate8(uint8_t value): m_value(value)
+{}
+
+uint8_t Asm::Args::Immediate8::value() const
+{
+ return m_value;
+}
+
+std::vector<uint8_t> Asm::Args::Immediate8::getCode() const
+{
+ return {m_value};
+}
+
+Asm::Args::Immediate16::Immediate16(uint16_t value): m_value(value)
+{}
+
+uint16_t Asm::Args::Immediate16::value() const
+{
+ return m_value;
+}
+
+std::vector<uint8_t> Asm::Args::Immediate16::getCode() const
+{
+ return endian::to_little(m_value);
+}
+
+Asm::Args::Immediate32::Immediate32(uint32_t value): m_value(value)
+{}
+
Asm::Args::Immediate32::Immediate32(const Asm::Args::Immediate64& imm64)
{
if (imm64.value() < 0x100000000)
@@ -10,23 +41,144 @@ Asm::Args::Immediate32::Immediate32(const Asm::Args::Immediate64& imm64)
throw std::runtime_error("Immediate32: Constructed from too big Immediate64");
}
-Asm::Args::Mem8Ptr64::Mem8Ptr64(const std::string& reg, int32_t offs): m_reg(reg), m_offs(offs) {}
-Asm::Args::Mem8Ptr64::Mem8Ptr64(const std::string& reg, const std::string& reg2, int32_t offs): m_reg(reg), m_reg2(reg2), m_offs(offs) {}
-std::string Asm::Args::Mem8Ptr64::reg() const { return "["s + m_reg + "]"s; }
-std::string Asm::Args::Mem8Ptr64::reg2() const { return "["s + m_reg2 + "]"s; }
-int32_t Asm::Args::Mem8Ptr64::offs() const { return m_offs; }
+uint32_t Asm::Args::Immediate32::value() const
+{
+ return m_value;
+}
+
+std::vector<uint8_t> Asm::Args::Immediate32::getCode() const
+{
+ return endian::to_little(m_value);
+}
+
+Asm::Args::Immediate64::Immediate64(uint64_t value): m_value(value)
+{}
+
+uint64_t Asm::Args::Immediate64::value() const
+{
+ return m_value;
+}
+
+std::vector<uint8_t> Asm::Args::Immediate64::getCode() const
+{
+ return endian::to_little(m_value);
+}
+
+Asm::Args::Register8::Register8(const std::string& name): m_name(name)
+{}
+
+std::string Asm::Args::Register8::name() const
+{
+ return m_name;
+}
+
+Asm::Args::Register16::Register16(const std::string& name): m_name(name)
+{}
+
+std::string Asm::Args::Register16::name() const
+{
+ return m_name;
+}
+
+Asm::Args::Register32::Register32(const std::string& name): m_name(name)
+{}
+
+std::string Asm::Args::Register32::name() const
+{
+ return m_name;
+}
+
+Asm::Args::Register64::Register64(const std::string& name): m_name(name)
+{}
+
+std::string Asm::Args::Register64::name() const
+{
+ return m_name;
+}
+
+Asm::Args::Mem8Ptr64::Mem8Ptr64(const std::string& reg, int32_t offs): m_reg(reg), m_offs(offs)
+{}
+
+Asm::Args::Mem8Ptr64::Mem8Ptr64(const std::string& reg, const std::string& reg2, int32_t offs): m_reg(reg), m_reg2(reg2), m_offs(offs)
+{}
+
+std::string Asm::Args::Mem8Ptr64::reg() const
+{
+ return "["s + m_reg + "]"s;
+}
+
+std::string Asm::Args::Mem8Ptr64::reg2() const
+{
+ return "["s + m_reg2 + "]"s;
+}
+
+int32_t Asm::Args::Mem8Ptr64::offs() const
+{
+ return m_offs;
+}
+
+Asm::Args::Mem16Ptr64::Mem16Ptr64(const std::string& reg, int32_t offs): m_reg(reg), m_offs(offs)
+{}
+
+Asm::Args::Mem16Ptr64::Mem16Ptr64(const std::string& reg, const std::string& reg2, int32_t offs): m_reg(reg), m_reg2(reg2), m_offs(offs)
+{}
+
+std::string Asm::Args::Mem16Ptr64::reg() const
+{
+ return "["s + m_reg + "]"s;
+}
-Asm::Args::Mem32Ptr64::Mem32Ptr64(const std::string& reg, int32_t offs): m_reg(reg), m_offs(offs) {}
-Asm::Args::Mem32Ptr64::Mem32Ptr64(const std::string& reg, const std::string& reg2, int32_t offs): m_reg(reg), m_reg2(reg2), m_offs(offs) {}
-std::string Asm::Args::Mem32Ptr64::reg() const { return "["s + m_reg + "]"s; }
-std::string Asm::Args::Mem32Ptr64::reg2() const { return "["s + m_reg2 + "]"s; }
-int32_t Asm::Args::Mem32Ptr64::offs() const { return m_offs; }
+std::string Asm::Args::Mem16Ptr64::reg2() const
+{
+ return "["s + m_reg2 + "]"s;
+}
+
+int32_t Asm::Args::Mem16Ptr64::offs() const
+{
+ return m_offs;
+}
-Asm::Args::Mem64Ptr64::Mem64Ptr64(const std::string& reg, int32_t offs): m_reg(reg), m_offs(offs) {}
-Asm::Args::Mem64Ptr64::Mem64Ptr64(const std::string& reg, const std::string& reg2, int32_t offs): m_reg(reg), m_reg2(reg2), m_offs(offs) {}
-std::string Asm::Args::Mem64Ptr64::reg() const { return "["s + m_reg + "]"s; }
-std::string Asm::Args::Mem64Ptr64::reg2() const { return "["s + m_reg2 + "]"s; }
-int32_t Asm::Args::Mem64Ptr64::offs() const { return m_offs; }
+Asm::Args::Mem32Ptr64::Mem32Ptr64(const std::string& reg, int32_t offs): m_reg(reg), m_offs(offs)
+{}
+
+Asm::Args::Mem32Ptr64::Mem32Ptr64(const std::string& reg, const std::string& reg2, int32_t offs): m_reg(reg), m_reg2(reg2), m_offs(offs)
+{}
+
+std::string Asm::Args::Mem32Ptr64::reg() const
+{
+ return "["s + m_reg + "]"s;
+}
+
+std::string Asm::Args::Mem32Ptr64::reg2() const
+{
+ return "["s + m_reg2 + "]"s;
+}
+
+int32_t Asm::Args::Mem32Ptr64::offs() const
+{
+ return m_offs;
+}
+
+Asm::Args::Mem64Ptr64::Mem64Ptr64(const std::string& reg, int32_t offs): m_reg(reg), m_offs(offs)
+{}
+
+Asm::Args::Mem64Ptr64::Mem64Ptr64(const std::string& reg, const std::string& reg2, int32_t offs): m_reg(reg), m_reg2(reg2), m_offs(offs)
+{}
+
+std::string Asm::Args::Mem64Ptr64::reg() const
+{
+ return "["s + m_reg + "]"s;
+}
+
+std::string Asm::Args::Mem64Ptr64::reg2() const
+{
+ return "["s + m_reg2 + "]"s;
+}
+
+int32_t Asm::Args::Mem64Ptr64::offs() const
+{
+ return m_offs;
+}
namespace {