简体   繁体   English

使用AsmJit引用全局变量

[英]Referring global variable with AsmJit

I need to to load an address of an existing global variable/ exernal variable to a register with a lea operation. 我需要使用lea操作将现有全局变量/外部变量的地址加载到寄存器中。 Is this possible in AsmJit? 这在AsmJit中可行吗? The associated ptr function only seem to accept GpVar which needs to be created within AsmJit. 关联的ptr函数似乎只接受需要在AsmJit中创建的GpVar。

There are multiple ways of doing this. 有多种方法可以做到这一点。 The most portable and recommended way would be to use mov reg, imm : 最可移植和推荐的方法是使用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. lea reg,mem具有绝对地址[mem]形式。 This solution works as expected only in 32-bit mode; 该解决方案仅在32位模式下可以正常工作。 the absolute address size is always truncated to 32 bits: 绝对地址大小始终被截断为32位:

c.lea(var, ptr_abs(p));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM