.intel_syntax noprefix
.data # section declaration
msg: .ascii "Hello, world!\n" # our dear string
len = . - msg # length of our dear string
msg_p: .int msg
len_p: .int len
.text # section declaration
# we must export the entry point to the ELF linker or
.global _start # loader. They conventionally recognize _start as
their
# entry point. Use ld -e foo to override the default.
_start:
# write our string to stdout
mov edx, [len_p] #third argument: message length
mov ecx, [msg_p] #second argument: pointer to message to
write
mov ebx, 1 #first argument: file handle (stdout)
mov eax, 4 #system call number (sys_write)
int 0x80 #call kernel
# and exit
mov ebx, 0 #first syscall argument: exit code
mov eax, 1 #system call number (sys_exit)
int 0x80 #call kernel
The problem is that is i use
mov ecx, msg #second argument: pointer to message to write
to place the adress of the message in ecx, for some reason GAS takes
msg to be a memory adress and generates the code:
mov ecx, [msg] #second argument: pointer to message to
write
Any one knows a away around this????
Paulo Lopes
Without ".intel_syntax noprefix", "$msg". With ".intel_syntax", try
"offset msg". If that doesn't work, try "offset flat: msg" (I think
that's an old one).
Best,
Frank
Nice!!! offset msg works, but can you tell me were is the
documentation for that?
Paulo Lopes
...
> Nice!!! offset msg works, but can you tell me were is the
> documentation for that?
No. When ".intel_syntax" was a new thing, I discovered "offset flat:" by
looking at the source code (not the recommended method!). I also found
the name of the woman who wrote the code (Catherine Greene, IIRC), and
wrote to her about documentation. She replied that she had "just reverse
engineered some stuff" they got from Intel. There *may* be some
documentation for it now, but I don't know where to find it. Sorry.
Best,
Frank