Skip to content

Commit 23d8f70

Browse files
committed
x86 asm: move gnu gas char literals from x86-assembly-cheat
1 parent d62070d commit 23d8f70

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

README.adoc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12363,6 +12363,20 @@ When reading disassembly, many instructions have either a `.n` or `.w` suffix.
1236312363

1236412364
Bibliography: https://stackoverflow.com/questions/27147043/n-suffix-to-branch-instruction
1236512365

12366+
==== GNU GAS assembler char literals
12367+
12368+
link:userland/arch/x86_64/char_literals.S[]
12369+
12370+
http://stackoverflow.com/questions/33246811/how-to-use-character-literals-in-gnu-gas-to-replace-numbers
12371+
12372+
This syntax plays horribly with the C preprocessor:
12373+
12374+
....
12375+
MACRO($'a)
12376+
....
12377+
12378+
fails because cpp treats string and char literals magically.
12379+
1236612380
=== NOP instructions
1236712381

1236812382
* x86: link:userland/arch/x86_64/nop.S[NOP]

userland/arch/x86_64/char_literals.S

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/* https://github.com/cirosantilli/linux-kernel-module-cheat#gnu-gas-assembler-char-literals */
2+
3+
#include <lkmc.h>
4+
5+
LKMC_PROLOGUE
6+
mov $0, %r12
7+
8+
/* Memory. */
9+
mov mychar, %r12b
10+
LKMC_ASSERT_EQ(%r12, $0x61)
11+
12+
/* Immediate. Without the `$`, does a memory access, and segfaults! */
13+
mov $'b, %r12b
14+
LKMC_ASSERT_EQ(%r12, $0x62)
15+
16+
/* Space character works. */
17+
mov $' , %r12b
18+
LKMC_ASSERT_EQ(%r12, $0x20)
19+
20+
/* Backslash escapes work. */
21+
mov $'\n , %r12b
22+
LKMC_ASSERT_EQ(%r12, $0x0A)
23+
LKMC_EPILOGUE
24+
mychar:
25+
.byte 'a

0 commit comments

Comments
 (0)