[cfe-dev] GNU assembler syntax for strlen
Andrew Pennebaker
andrew.pennebaker at gmail.com
Tue Oct 16 04:00:54 PDT 2012
My Hello World assembler<https://github.com/mcandre/mcandre/tree/master/gas/hello/freebsd>only
works if I hardcode the message length. If I try to use pseudo-ops to
calculate the length, the program either prints extra garbage, or fails to
build.
Code:
msg: .asciz "Hello World!\n"
...
push $14
push $msg
...
Trace:
$ clang -c -o hello.o -arch i386 hello.s
$ ld -o hello -macosx_version_min 10.6 -arch i386 hello.o
$ ./hello
Hello World!
Code:
msg: .asciz "Hello World!\n"
*len: .long .-msg*
...
push $len
push $msg
...
Trace:
$ clang -c -o hello.o -arch i386 hello.s
$ ld -o hello -macosx_version_min 10.6 -arch i386 hello.o
$ ./hello
Hello World!
?';? msgstdoutsys_exitsys_writekernel__mh_execute_headerstart
Code:
msg: .asciz "Hello World!\n"
*len = .-msg*
...
push $len
push $msg
...
Trace:
$ clang -c -o hello.o -arch i386 hello.s
$ ld -o hello -macosx_version_min 10.6 -arch i386 hello.o
ld: section __data (address=0x00002000, size=4294967279) would make the
output executable exceed available address range for architecture i386
What is the proper syntax for calculating the length of a hardcoded string
in Clang/Gas? In NASM, I write len equ $-msg
--
Cheers,
Andrew Pennebaker
www.yellosoft.us
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20121016/3000ad6d/attachment.html>
More information about the cfe-dev
mailing list