I know that the .ascii
directive doesn't put a null character at the end of the string, as the .asciz
directive is used for that purpose. However, I don't know whether the .string
directive puts a null character at the end of the string.
If it does append the null character, then what's the difference between the .asciz
and the .string
directives? To me, having both .asciz
and .string
seems redundant.
According to the binutils docs:
.ascii "string"
(Here for completeness).asciz "string"
.string "str", .string8 "str", .string16 "str", .string32 "str", .string64 "str"
They all support escape sequences and accept multiple arguments. As for the difference between
.string
and.asciz
:.string
will not add the null byte, when.asciz
always will. To test your own system, you can do this:echo '.string ""' | gcc -c -o stdout.o -xassembler -; objdump -sj .text stdout.o
..string
also has suffixes to expand characters to certain widths (16, 32, or 64), but by default it is 8.As stated in the comments to the question, in most cases, there is no difference other than semantics, but technically, the two pseudo-ops are different.
Addendum:
As it turns out, the docs do mention two architectures that behave differently:
.stringz
directive for that..pstring
directive that packs the characters and zero-fills unused space.Digging through the source code in the
gas/config
folder, we can confirm this and find one more:.string
and.stringz
behave like HPPA.