且构网

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

GNU汇编器,点号(现住址)

更新时间:2021-11-17 03:03:01

您忘了告诉你如何使用的值。如果你这样做 MOVL lenhello,EDX%它应该工作的罚款。我假设你做了 MOVL $ lenhello,EDX%代替。

You have forgotten to show how you use the value. If you do movl lenhello, %edx it should work fine. I assume you did movl $lenhello, %edx instead.

.EQU 指令定义一个符号,其价值将是长度,所以你会引用为 $ lenhello 。它不保留任何内存。用你的第二个版本,您可以定义在内存中包含长度可变的。 $ lenhello 在这种情况下将是你的变量的地址,而不是长度。

The .equ directive defines a symbol whose value will be the length, so you will reference that as $lenhello. It doesn't reserve any memory. Using your second version, you define a variable in memory that contains the length. $lenhello in that case will be the address of your variable, and not the length.

全部样本code:

.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

这无关与符号。