Get a variable value to a register with AsmJit

438 views Asked by At

How can I get a variable value to a register using AsmJit API? Some thing like below?

int x = 234;
Assember a;
a.mov(rax, $value_of_x);
1

There are 1 answers

0
Petr On BEST ANSWER

AsmJit supports immediate operands, all you need is:

using namespace asmjit;

// Create and configure X86Assembler:
X86Assembler a(...);

// The answer:
int x = 234;
a.mov(x86::rax, x);

or just

a.mov(x86::rax, 234);

The previous examples used function overloads that accept immediate values directly. However, it's also possible to create the Imm operand and use it in your code dynamically:

Imm x = imm(234);
a.mov(x86::rax, x);

Or:

a.mov(x86::rax, imm(x));