Reputation: 145
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
After calling sys_write function first code works fine, but the second one apart from writing hello world produces a lot of trash
Upvotes: 0
Views: 869
Reputation: 58762
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.
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.
Full sample 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
It has nothing to do with the .
symbol.
Upvotes: 1