what does “.=” means in AT&T assembly language?

前端 未结 1 1440
粉色の甜心
粉色の甜心 2021-01-15 01:14

I am trying to code a boot program.The contents like following:

.text
balabala
.globl _start
_start:
balabala

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

相关标签:
1条回答
  • 2021-01-15 01:45

    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.

    Using your example modified:

    SOMEDATA:
        .byte 0x55,0xaa
    

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

    If I added immediately afterwards

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

    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
    

    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.

    0 讨论(0)
提交回复
热议问题