Assembly GNU汇编程序,点符号(当前地址)
我想问,为什么写这样的东西是可以的:Assembly GNU汇编程序,点符号(当前地址),assembly,gnu,Assembly,Gnu,我想问,为什么写这样的东西是可以的: .section .data hello: .ascii "Hello World\n" .equ lenhello, . - hello 但我键入以下内容时不正确: .section .data hello: .ascii "Hello World\n" lenhello: .long . - hello 调用sys_write函数后,第一个代码工作正常,但除了编写hello world之外的第二个代码会产生大量垃圾您忘记了如何
.section .data
hello:
.ascii "Hello World\n"
.equ lenhello, . - hello
但我键入以下内容时不正确:
.section .data
hello:
.ascii "Hello World\n"
lenhello:
.long . - hello
调用sys_write函数后,第一个代码工作正常,但除了编写hello world之外的第二个代码会产生大量垃圾您忘记了如何使用该值。如果您执行
movl lenhello,%edx
操作,应该可以正常工作。我想你是这样做的,movl$lenhello,%edx
.eq
指令定义了一个值为长度的符号,因此您可以将其引用为$lenhello
。它不保留任何内存。使用第二个版本,在内存中定义一个包含长度的变量$lenhello
在这种情况下,将是变量的地址,而不是长度
完整示例代码:
.section .data
hello:
.ascii "Hello World\n"
lenhello:
.long . - hello
.text
.globl _start
_start:
movl $1, %ebx
movl $hello, %ecx
movl lenhello, %edx
movl $4, %eax
int $0x80
movl $1, %eax
movl $0, %ebx
int $0x80
它与
符号无关