本文介绍了GNU汇编器,点号(现住址)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想问一下,为什么它是确定这样写的:

I would like to ask why it is ok to write something like this:

.section .data
hello:
    .ascii "Hello World\n"
.equ lenhello, . - hello

但它是不正确的,当我键入:

but it is not right when i type:

.section .data
hello:
    .ascii "Hello World\n"
lenhello:
    .long . - hello

在调用后SYS_WRITE函数首先code正常工作,但除了编写的Hello World第二个产生了很多垃圾

After calling sys_write function first code works fine, but the second one apart from writing hello world produces a lot of trash

推荐答案

您忘了告诉你如何使用的值。如果你这样做 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

这无关与符号。

这篇关于GNU汇编器,点号(现住址)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-12 22:48