assemblyasmjit

Get a variable value to a register with AsmJit


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);

Solution

  • 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));