繁体   English   中英

AT&T组装中的匿名标签

[英]Anonymous labels in AT&T assembly

有没有一种方法可以跳到AT&T程序集中的下一个/上一个标签而又不妨碍名称空间,例如Intel语法中的 jmp @f

是。 这称为“本地标签”,甚至比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\0"            # Local label
    3:                          # Local label
    mov $2b,%ecx                # Pointer to the string "\n"
    mov $1,%edx                 # strlen = 1 byte to write
    mov $1,%ebx                 # STDOUT
    mov $4,%eax                 # WRITE
    int $0x80                   # 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 $1,%ebx                 # STDOUT
    mov $4,%eax                 # WRITE
    int $0x80                   # 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 $1,%eax                 # EXIT
    int $0x80                   # Call kernel

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM