且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

“.="是什么意思?在 AT&T 汇编语言中是什么意思?

更新时间:2022-06-05 02:52:09

汇编器将数据和指令转换为字节.与编译器不同,汇编指令和内存之间通常存在 1:1 匹配.这 .符号传统上用于表示当前程序段开始处的当前偏移量.

The assembler converts data and instructions into bytes. Unlike a compiler, there is generally a 1:1 matching between assembly instructions and memory. The . symbol has traditionally been used to indicate the current offset from the start of the current program section.

最常用于确定物体的大小.

It is most commonly used to determine the size of objects.

使用您修改的示例:

SOMEDATA:
    .byte 0x55,0xaa

这会分配 2 个字节,其值为 55 和 AA,并将内部标签 SOMEDATA 分配给具有该数据的位置.

This allocates 2 bytes with the value 55 and AA and assigns the internal label SOMEDATA to the location with that data.

如果我之后立即添加

SOMEDATA:
    .byte 0x55,0xaa
SOMEDATALENGTH = . - SOMEDATA

这将定义一个符号,给出分配的字节数(在这种情况下为 2).一些汇编器具有复杂的宏功能,可以描述复杂的数据结构.使用 .在设置此类结构时非常常见.

that would define a symbol giving the number of bytes allocated (2 in this case). Some assemblers have complex macro capabilities that can describe elaborate data structures. Using . is very common in setting up such structures.

一些汇编器允许分配给 .符号如上.

Some assemblers allow assignment to the . symbol as above.

_start:
.=_start+510
 .byte 0x55,0xaa

这会使分配器增加 510 个字节.然后它在位置 _start 和给定值 55 和 AA 的 2 个字节之间创建一个 510 字节的间隙.通常间隙用零填充,但这取决于汇编程序.

This causes the allocator to be incremented by 510 bytes. It then creates a 510 byte gap between the location _start and the 2 bytes given the value 55 and AA. Usually the gap is filled with zeros but that depends upon the assembler.