如何在地址计算中使用标签 [英] How do I use labels in address calculations

查看:50
本文介绍了如何在地址计算中使用标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下内联汇编代码段:

I have the following snippet of inline assembly:

procedure Foo;
asm
//.....
@partialloop: shr rdx,1              //every instruction is 4 bytes
              lea r11,[rip + (7*4)+(@partial-@offset)]
@offset:      sub r11,rdx
              xor r8,r8
              jmp r11                //do a partial loop
@loop64:      mov [rcx],rax
@partial:     mov [rcx+08H],rax
//....
end;

编译器不接受以下语法:

The compiler does not accept this syntax:

E2105内联汇编器语法错误

E2105 Inline assembler syntax error

创建对 offset ptr @@ 的使用无济于事.

Create use of offset, ptr or @@ does not help.

我需要使用哪种语法进行编译?

What syntax do I need to use to make this compile?

推荐答案

它不起作用,因为不需要此构造.
编译器不允许使用这些构造来防止代码中的逻辑错误.

It does not work, because there is no need for this construct.
The compiler disallows these constructs to prevent logical errors in code.

以下代码段实际上是正确的:

The following snippet is actually correct:

@partialloop: shr rdx,1              //every instruction is 4 bytes
              lea r11,[rip + @partial + (7*4)] //r11= end of the loop
@offset:      sub r11,rdx            //step back as needed
              xor r8,r8              //only do a single iteration
              jmp r11                //do a partial loop
@loop64:      mov [rcx],rax
@partial:     mov [rcx+08H],rax
//....
end;

表达式: [rip + @partial +(4 * 7)] 计算如下:

  • rip(此说明后的IP).
  • @partial裂口和该标签之间的距离.
  • (7 * 4)在所有其他内容之上的附加偏移量

在计算中使用 @label 总是会产生偏移量,而不是绝对值. jmp @label 总是转换为相对跳转,而不是绝对跳转.

Using a @label in calculations always yields an offset, not an absolute value. A jmp @label always translates into a relative jump, never an absolute jmp.

原始语句(如果编译器允许)当然也是正确的:

The original statement (if allowed by the compiler) would of course also be correct:

lea r11,[rip + (7*4)+(@partial-@offset)]
r11 = rip($6B74FB) + 28 + @partial($0C) - @offset(0)  

但是,由于RIP已经等于@offset的绝对地址,因此无需将其包含两次.

But because RIP is already equal to the absolute address of @offset there is no need to include it twice.

这篇关于如何在地址计算中使用标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆