How to use character literals in GNU GAS to replace numbers?

孤者浪人 提交于 2020-08-10 05:25:35

问题


For example, I'd like to write something like 'a' instead of 0x61 like I can in C.

The manual mentions them at: https://sourceware.org/binutils/docs/as/Chars.html but without an example I'm not sure I understood.


回答1:


/* 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 */

GitHub upstream.

There was actually an example at: 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:

  • 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


来源:https://stackoverflow.com/questions/33246811/how-to-use-character-literals-in-gnu-gas-to-replace-numbers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!