0

I need to to load an address of an existing global variable/ exernal variable to a register with a lea operation. Is this possible in AsmJit? The associated ptr function only seem to accept GpVar which needs to be created within AsmJit.

auselen
  • 27,577
  • 7
  • 73
  • 114
chamibuddhika
  • 1,419
  • 2
  • 20
  • 36

1 Answers1

1

There are multiple ways of doing this. The most portable and recommended way would be to use mov reg, imm:

using namespace asmjit;
using namespace asmjit::host;

// You have to initialize these...
Compiler c;

GpVar var(c, kVarTypeIntPtr);

void* p = NULL;
c.mov(var, imm_ptr(p));

Or lea reg, mem having an absolute address [mem] form. This solution works as expected only in 32-bit mode; the absolute address size is always truncated to 32 bits:

c.lea(var, ptr_abs(p));
Petr
  • 750
  • 6
  • 8