本文介绍了是否有重新presents在GNU GAS汇编当前地址的符号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我很好奇,想知道有没有什么特殊气体语法来达到相同的像NASM例如:

I am curious to know is there any special GAS syntax to achieve the same like in NASM example:

SECTION .data

    msg:    db "Hello World",10,0  ; the 0-terminated string.
    len:    equ $-msg              ; "$" means current address.

特别是我感兴趣的符号 $ 重新presenting当前的地址。

Especially I'm interested in the symbol $ representing the current address.

推荐答案

有是天然气和NASM之间的比较好用此处的

There is a useful comparison between gas and NASM here: http://www.ibm.com/developerworks/linux/library/l-gas-nasm/index.html

特别见这一部分,我想地址你的问题:

See in particular this part, which I think addresses your question:

清单2还引入了位置计数器(6号线)的概念。 NASM提供特殊的变量($和$$变量)来操作位置计数器。气,没有操纵位置计数器方法,你必须使用标签计算下一个存储位置(数据,指令等)。
例如,要计算一个字符串的长度,你可以使用下面的语句在NASM:

Listing 2 also introduces the concept of a location counter (line 6). NASM provides a special variable (the $ and $$ variables) to manipulate the location counter. In GAS, there is no method to manipulate the location counter and you have to use labels to calculate the next storage location (data, instruction, etc.).For example, to calculate the length of a string, you would use the following idiom in NASM:

prompt_str db 'Enter your name: '
STR_SIZE equ $ - prompt_str     ; $ is the location counter

在$给出了位置计数器的当前值,并减去标签(所有变量名都是标签),从这个位置计数器的值给出字节present的标签上的声明与电流之间的数位置。 EQU指令用于设置变量STR_SIZE到EX pression跟随它的价值。在气体中类似的成语是这样的:

The $ gives the current value of the location counter, and subtracting the value of the label (all variable names are labels) from this location counter gives the number of bytes present between the declaration of the label and the current location. The equ directive is used to set the value of the variable STR_SIZE to the expression following it. A similar idiom in GAS looks like this:

prompt_str:
     .ascii "Enter Your Name: "

pstr_end:
     .set STR_SIZE, pstr_end - prompt_str

结束标签(pstr_end)给出下一个位置地址,减去起始标志地址给人的大小。还要注意使用.SET到变量STR_SIZE的值初始化为前pression逗号以下。对应的.EQU也可以使用。没有办法,在NASM GAS的一套指令。

The end label (pstr_end) gives the next location address, and subtracting the starting label address gives the size. Also note the use of .set to initialize the value of the variable STR_SIZE to the expression following the comma. A corresponding .equ can also be used. There is no alternative to GAS's set directive in NASM.

这篇关于是否有重新presents在GNU GAS汇编当前地址的符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 03:11