做任何语言/编译器利用86键指令非零嵌套层次? [英] Do any languages / compilers utilize the x86 ENTER instruction with a nonzero nesting level?

查看:192
本文介绍了做任何语言/编译器利用86键指令非零嵌套层次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

那些熟悉x86汇编程序设计也很习惯典型的函数序言/结尾:

Those familiar with x86 assembly programming are very used to the typical function prologue / epilogue:

push ebp
mov  esp, ebp
sub  esp, [size of local variables]
...
mov  esp, ebp
pop  ebp
ret

这同样code的顺序也可以用 ENTER 退出指令来实现p>

This same sequence of code can also be implemented with the ENTER and LEAVE instructions:

enter [size of local variables], 0
...
leave
ret

ENTER 指令的第二个操作数是嵌套级别的,它允许从被调用函数访问多个父帧。

The ENTER instruction's second operand is the nesting level, which allows multiple parent frames to be accessed from the called function.

这是不是在C使用,因为没有嵌套函数;局部变量只有他们在声明的功能范围这个结构不存在(虽然有时我希望它做):

This is not used in C because there are no nested functions; local variables have only the scope of the function they're declared in. This construct does not exist (although sometimes I wish it did):

void func_a(void)
{
    int a1 = 7;

    void func_b(void)
    {
        printf("a1 = %d\n", a1);  /* a1 inherited from func_a() */
    }

    func_b();
}

不过的Python的确实的有嵌套它们的行为这样的功能:

Python however does have nested functions which behave this way:

def func_a():
    a1 = 7
    def func_b():
        print 'a1 = %d' % a1      # a1 inherited from func_a()
    func_b()

当然Python的code是不会被直接翻译为x86机器code,并因此将无法(不可能?)取本指令的优势。

Of course Python code isn't translated directly to x86 machine code, and thus would be unable (unlikely?) to take advantage of this instruction.

是否有编译为x86和提供嵌套函数任何语言?有没有这将发出一个编译器 ENTER 指令非零第二个操作?

Are there any languages which compile to x86 and provide nested functions? Are there compilers which will emit an ENTER instruction with a nonzero second operand?

英特尔投资的时间非零量/钱成嵌套级别操作,基本上我,如果有人使用它只是好奇: - )

Intel invested a nonzero amount of time/money into that nesting level operand, and basically I'm just curious if anyone uses it :-)

参考文献:

  • Intel® 64 and IA-32 Architectures Software Developer’s Manual Vol 2: Instruction Set Reference
  • NASM Manual - ENTER: Create Stack Frame

推荐答案

输入避免在实践中,因为它表现相当糟糕 - 看到答案在<一个href=\"http://stackoverflow.com/questions/5959890/enter-vs-push-ebp-mov-ebp-esp-sub-esp-imm-and-leave-vs-mov-esp-ebp\">"enter" VS&QUOT;推EBP; MOV EBP,ESP;子ESP,IMM&QUOT;和&QUOT;假&QUOT; VS&QUOT; MOV ESP,EBP;流行EBP&QUOT; 。但是也有一些过时,但仍然支持向后兼容的原因一堆x86指令 - 输入就是其中的一个。 (离开是OK,虽然,编译器高兴地发出它。)

enter is avoided in practice as it performs quite poorly - see the answers at "enter" vs "push ebp; mov ebp, esp; sub esp, imm" and "leave" vs "mov esp, ebp; pop ebp". There are a bunch of x86 instructions that are obsolete but are still supported for backwards compatibility reasons - enter is one of those. (leave is OK though, and compilers are happy to emit it.)

充分执行一般性嵌套功能在Python实际上是比简单地选择一些帧管理指令相当多有趣的问题 - 搜索'封闭转换和向上/向下funarg问题,你会发现很多有趣的讨论

Implementing nested functions in full generality as in Python is actually a considerably more interesting problem than simply selecting a few frame management instructions - search for 'closure conversion' and 'upwards/downwards funarg problem' and you'll find many interesting discussions.

请注意,在x86最初被设计为一个Pascal机,这就是为什么有支持嵌套函数指令(输入离开)的帕斯卡尔调用约定中被调用弹出一个已知数量的参数从栈( RET氏/ code>),边界检查(约束),依此类推。许多这些操作都已经被淘汰。

Note that the x86 was originally designed as a Pascal machine, which is why there are instructions to support nested functions (enter, leave), the pascal calling convention in which the callee pops a known number of arguments from the stack (ret K), bounds checking (bound), and so on. Many of these operations are now obsolete.

这篇关于做任何语言/编译器利用86键指令非零嵌套层次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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