AT&T 汇编中的匿名标签

Anonymous labels in AT&T assembly

有没有一种方法可以跳转到 AT&T 程序集中的 next/previous 标签而不影响命名空间,例如 jmp @f in the Intel syntax?

是的。这称为 "local labels" 并且比 MASM/FASM 变体更强大:

https://sourceware.org/binutils/docs/as/Symbol-Names.html#Local-Labels-1

标签只有一个数字。向前或向后跳转用这个数字指定。

示例(m_newlinejne 1b 中的标签 2 和 3 接近尾声):

.macro m_newline
    jmp 3f                      # Skip over data
    2: .ascii "\n[=10=]"            # Local label
    3:                          # Local label
    mov b,%ecx                # Pointer to the string "\n"
    mov ,%edx                 # strlen = 1 byte to write
    mov ,%ebx                 # STDOUT
    mov ,%eax                 # WRITE
    int [=10=]x80                   # Call kernel
.endm

.macro m_strlen                 # ESI = Pointer to zero terminated string
    mov %esi, %edi              # ES:EDI for scasb
    mov $-1, %ecx               # ECX = max
    xor %al, %al                # Search for zero
    repnz scasb
    mov %edi, %edx
    sub %esi, %edx
    dec %edx                    # EDX = strlen
    mov %esi, %ecx              # ECX = Pointer to the string
.endm

.macro m_puts
    m_strlen                    # ESI -> EDX and ECX
    mov ,%ebx                 # STDOUT
    mov ,%eax                 # WRITE
    int [=10=]x80                   # Call kernel
    m_newline                   # Write new line
.endm

.text
_start:

    xor %eax, %eax

    1:
    mov 4(%esp,%eax,4),%esi     # mov esi, [esp + eax * 4 + 4]

    push %eax
    m_puts
    pop %eax

    inc %eax
    cmp (%esp), %eax
    jne 1b                      # backwards to the previous label "1"

    mov (%esp),%ebx             # Exitcode
    mov ,%eax                 # EXIT
    int [=10=]x80                   # Call kernel