两个偏移了Visual-C ++内联汇编的区别 [英] Visual-C++ inline assembler difference of two offsets

查看:207
本文介绍了两个偏移了Visual-C ++内联汇编的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我移植code的大块从MASM到C内联汇编(X86的Windows,MS VC)
Foolowing是不是一个真正的code,只是恶搞出出主意。比方说,我定义为静态数组或甚至$ C两个标签之间$ C块的一些数据,我需要得到它的大小。

I'm porting chunk of code from MASM to C inline assembler (x86, Windows, MS VC) Foolowing is not a real code, just spoof to give an idea. Let's say I have some data defined as static array or even a code chunk between two labels, and I need to get size of it.

    label1:
    bla bla bla
    label2:
    ....
    mov eax, (offset label2 - offset label1)

这样的code工作在MASM就像一个魅力,但在C我得到以下错误信息:
错误C2425:' - ':在'第二个操作数非恒前pression
我可以编译:

Such a code works in MASM like a charm, but in C I get following error message: "error C2425: '-' : non-constant expression in 'second operand'" I can get compiled:

    mov eax, offset label1
    mov eax, offset label2

我希望编译器来评估(偏移卷标1 - 偏移LABEL2)在编译时,但它看起来像我错了。我不能添加偏移以及(为什么?这些都只是在编译过程中加入了两个整数...?)
当然,我可以得到
        MOV EAX,抵消LABEL2
        MOV EDX,偏移LABEL1
        子EAX,EDX
编译,但是这只是用于计算一个常数一个额外的code。
有人可以解释我请,什么是错的,我code?

I expect compiler to evaluate (offset label1 - offset label2) at compile time, but it looks like I'm wrong. I can't add offsets as well (why? these are just two integers added during compilation...?) Sure, I can get mov eax, offset label2 mov edx, offset label1 sub eax, edx compiled, but that's an extra code just for calculating a constant. Can someone explain me please, what is wrong in my code?

可不可以这样的东西造成的搬迁?如何通过推动它?

Can it be something caused by relocation? How to push it through?

期待一个答案,
谢谢你。

Looking forward to an answer, thank you.

推荐答案

是的,它可以通过搬迁的处理相对跳跃可变长度指令的威胁,而且威胁造成的。最有可能的是因为一些小麻烦,汇编了作家最简单的方式和实施了1通行证或两遍编译器,一旦做最后的决定越好。因而一些方便的前pressions不受支持。

Yes, it can be caused by the threat of relocation but also threat of variable length instructions dealing with relative jumps. Most likely because of some minor trouble, the assembler writers took the easy way out and implemented a 1 pass or a two pass compiler that makes final decisions as soon as possible. And thus some convenient expressions are unsupported.

由于在评论已经建议,汇编器仍可能支持MOV +子组合。

As already suggested in the comment, the assembler still probably supports mov + sub combination.

这篇关于两个偏移了Visual-C ++内联汇编的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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