本文介绍了gnu汇编程序:获取标签/变量的地址[INTEL SYNTAX]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的代码:

.bss
woof: .long 0

.text
bleh:
...some op codes here.

现在我想将woof的地址移入eax.用于执行此操作的 intel语法代码是什么?将bleh的地址移到ebx中也是如此.

now I would like to move the address of woof into eax. What's the intel syntax code here for doing that? The same goes with moving bleh's address into, say, ebx.

非常感谢您的帮助!

推荐答案

bss节中不能包含任何实际对象.某些汇编程序可能仍然允许您切换到.bss部分,但是您所能做的只是说:x: . = . + 4.

The bss section can't have any actual objects in it. Some assemblers may still allow you to switch to the .bss section, but all you can do there is say something like: x: . = . + 4.

如今,在大多数汇编程序中,尤其是在用于intel的gnu中,不再有.bss指令,因此您可以临时切换到bss并使用类似.comm sym,size,alignment的方式一次创建bss符号.这就是为什么您可能会收到错误. bss指令无法识别"或类似的错误的原因.

In most assemblers these days and specifically in gnu for intel, there is no longer a .bss directive, so you temporarily switch to bss and create the bss symbol in one shot with something like: .comm sym,size,alignment. This is why you are presumably getting an error ".bss directive not recognized" or something like that.

然后您可以使用以下任一地址获取地址:

And then you can get the address with either:

lea woof, %eax

movl $woof, %eax

更新:啊哈,intel语法,而不是intel体系结构.好:

Update: aha, intel syntax, not intel architecture. OK:

.intel_syntax noprefix
    lea    esi,fun
    lea    esi,[fun]
    mov     eax,OFFSET FLAT:fun
.att_syntax
    lea     fun, %eax
    mov     $fun, %eax
.data
fun: .long 0x123

所有lea表单都应生成相同的代码.

All the lea forms should generate the same code.

这篇关于gnu汇编程序:获取标签/变量的地址[INTEL SYNTAX]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 08:47