.asciz和.string汇编程序指令之间有什么区别? [英] What's the difference between the .asciz and the .string assembler directives?

查看:694
本文介绍了.asciz和.string汇编程序指令之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道.ascii指令不会在字符串末尾添加空字符,因为.asciz指令用于此目的.但是,我不知道.string指令是否在字符串的末尾放置一个空字符.

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.

如果确实添加了空字符,那么.asciz.string指令之间有什么区别?对我来说,同时拥有.asciz.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.

推荐答案

根据 .ascii "string"(此处为完整性)

.ascii期望零个或多个字符串文字,以逗号分隔.它将每个字符串(不带自动尾随零字节)组合成连续的地址.

.ascii expects zero or more string literals separated by commas. It assembles each string (with no automatic trailing zero byte) into consecutive addresses.

.asciz "string"

.asciz与.ascii一样,但是每个字符串后跟一个零字节. .asciz中的"z"代表零".

.asciz is just like .ascii, but each string is followed by a zero byte. The "z" in ‘.asciz’ stands for "zero".

.string "str", .string8 "str", .string16 "str", .string32 "str", .string64 "str"

.string "str", .string8 "str", .string16 "str", .string32 "str", .string64 "str"

将str中的字符复制到目标文件.您可以指定多个要复制的字符串,以逗号分隔.除非为特定机器另外指定,否则汇编器会用0字节标记每个字符串的结尾.

Copy the characters in str to the object file. You may specify more than one string to copy, separated by commas. Unless otherwise specified for a particular machine, the assembler marks the end of each string with a 0 byte.

...

变体string16,string32和string64与字符串伪操作码的不同之处在于,将str中的每个8位字符复制并分别扩展为16、32或64位.扩展的字符以目标字节顺序存储.

The variants string16, string32 and string64 differ from the string pseudo opcode in that each 8-bit character from str is copied and expanded to 16, 32 or 64 bits respectively. The expanded characters are stored in target endianness byte order.

它们都支持转义序列并接受多个参数.至于.string.asciz之间的区别:

They all support escape sequences and accept multiple arguments. As for the difference between .string and .asciz:

  • 在某些体系结构中,当.asciz始终添加时,.string不会添加空字节.要测试您自己的系统,可以执行以下操作:
    • echo '.string ""' | gcc -c -o stdout.o -xassembler -; objdump -sj .text stdout.o.
    • 如果第一个字节为00,则插入了空字符.
    • In certain architectures, .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.
      • If the first byte is 00, then the null character was inserted.

      如对问题的评论中所述,在大多数情况下,除了语义上没有其他区别,但是从技术上讲,这两个伪操作是不同的.

      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.

      附录:

      事实证明,文档 do 提到了两种行为不同的体系结构:

      As it turns out, the docs do mention two architectures that behave differently:

      • HPPA(HP精密体系结构)-不加0,但是为此添加了特殊的.stringz指令.
      • TI-C54X(得克萨斯仪器公司的某些DSP芯片)-每个字的高8位(2字节)为零.有一个相关的.pstring指令,该指令打包字符并将零填充未使用的空间.
      • HPPA (HP Precision Architecture) - does not add 0, but has a special .stringz directive for that.
      • TI-C54X (Some DSP chip from Texas Instruments) - zero-fills upper 8 bits of each word (2 bytes). Has a related .pstring directive that packs the characters and zero-fills unused space.

      gas/config文件夹中浏览源代码,我们可以确认这一点并找到另外一个:

      Digging through the source code in the gas/config folder, we can confirm this and find one more:

      • IA64(英特尔体系结构)-.string.stringz的行为类似于HPPA.
      • IA64 (Intel Architecture) - .string and .stringz behave like HPPA.

      这篇关于.asciz和.string汇编程序指令之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆