Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add memory operand overload for base+index*scale #128

Merged
merged 1 commit into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/assembler_basic/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 14 additions & 0 deletions zasm/include/zasm/x86/memory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
Loading