From a8f024ec7561f672996f611735ab9511f0adec51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Wed, 22 May 2024 21:26:49 +0300 Subject: [PATCH] Add memory operand overload for base+index*scale --- examples/assembler_basic/main.cpp | 1 + zasm/include/zasm/x86/memory.hpp | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/examples/assembler_basic/main.cpp b/examples/assembler_basic/main.cpp index 13337f2..f0f5375 100644 --- a/examples/assembler_basic/main.cpp +++ b/examples/assembler_basic/main.cpp @@ -17,6 +17,7 @@ int main() a.lea(x86::rax, x86::qword_ptr(labelA)); a.lea(x86::rbx, x86::qword_ptr(labelB)); a.lea(x86::rdx, x86::qword_ptr(labelC)); + a.movsx(x86::rax, x86::word_ptr(x86::rax, x86::rdx, 2)); a.bind(labelA); a.dq(0x123456789); diff --git a/zasm/include/zasm/x86/memory.hpp b/zasm/include/zasm/x86/memory.hpp index a8324ac..aba155c 100644 --- a/zasm/include/zasm/x86/memory.hpp +++ b/zasm/include/zasm/x86/memory.hpp @@ -29,6 +29,13 @@ namespace zasm::x86 return Mem(bitSize, Seg{}, base, index, 1, 0); } + // ptr [base + index * scale] + // ex.: mov eax, ptr [ecx+edx] + static constexpr Mem ptr(BitSize bitSize, const Gp& base, const Gp& index, int32_t scale) noexcept + { + return Mem(bitSize, Seg{}, base, index, scale, 0); + } + // ptr [base + index * scale + disp] // ex.: mov eax, ptr [ecx+edx*2+0xC] static constexpr Mem ptr(BitSize bitSize, const Gp& base, const Gp& index, int32_t scale, int64_t disp) noexcept @@ -99,6 +106,13 @@ namespace zasm::x86 return Mem(bitSize, seg, base, index, 1, 0); } + // ptr : seg [base + index * scale] + // ex.: mov eax, ptr:ds [edx+ecx*2+0xC] + static constexpr Mem ptr(BitSize bitSize, const Seg& seg, const Gp& base, const Gp& index, int32_t scale) noexcept + { + return Mem(bitSize, seg, base, index, scale, 0); + } + // ptr : seg [base + index * scale + disp] // ex.: mov eax, ptr:ds [edx+ecx*2+0xC] static constexpr Mem ptr(