如何在GNU GAS中使用字符文字替换数字? [英] How to use character literals in GNU GAS to replace numbers?
本文介绍了如何在GNU GAS中使用字符文字替换数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如,我想写像'a'
这样的东西,而不是像我在C语言中那样写的东西.
For example, I'd like to write something like 'a'
instead of 0x61
like I can in C.
手册在以下位置提及了它们: https://sourceware.org/binutils/docs/as/Chars.html ,但如果没有示例,我不确定我是否理解.
The manual mentions them at: https://sourceware.org/binutils/docs/as/Chars.html but without an example I'm not sure I understood.
推荐答案
/* Immediate. Without the `$`, does a memory access, and segfaults! */
mov $'a, %al
/* al == 0x61 */
/* Memory. */
mov c, %al
/* al == 0x62 */
c: .byte 'b
/* Space character works. */
mov $' , %al
/* al == 0x20 */
/* Backslash escapes work. */
mov $'\n , %al
/* al == 0x0A */
实际上有一个示例: https://sourceware.org/binutils/docs-2.25/as/Characters.html :
.byte 74, 0112, 092, 0x4A, 0X4a, 'J, '\J # All the same value.
由于以下原因,我不喜欢这种语法:
I dislike this syntax for the following reasons:
- 在C预处理器上不能很好地发挥作用:
MACRO($'a)
失败,因为cpp将'
视为char文字. - 可能会生成
$'
的尾随空格,这很难观察 - 不像C的
- does not play nicely with the C preprocessor:
MACRO($'a)
fails because cpp treats'
like a char literal. - may generate trailing whitespace as
$'
, which is hard to observe - not C-like
这篇关于如何在GNU GAS中使用字符文字替换数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文