Skip to content

Commit

Permalink
Add memory operand overload for base+index*scale
Browse files Browse the repository at this point in the history
  • Loading branch information
ZehMatt committed May 22, 2024
1 parent e0001ae commit a8f024e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
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

0 comments on commit a8f024e

Please sign in to comment.