Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 字符串常量中的新行字符为';nasm不承认这一点_Linux_Assembly_Nasm - Fatal编程技术网

Linux 字符串常量中的新行字符为';nasm不承认这一点

Linux 字符串常量中的新行字符为';nasm不承认这一点,linux,assembly,nasm,Linux,Assembly,Nasm,我正在用汇编程序编写一个“Hello world”程序。我已经声明了两个字符串常量,每个字符串末尾都有新行字符\n: section .data str1: db "abcd\n" str2: db "efgh\n" section .text global _start _start: mov rax, 1 mov rdi, 1 mov rsi, str1 mov rdx, 6 syscall

我正在用汇编程序编写一个“Hello world”程序。我已经声明了两个字符串常量,每个字符串末尾都有新行字符
\n

section .data
    str1: db "abcd\n"
    str2: db "efgh\n"

section .text
    global _start
_start:
    mov     rax, 1
    mov     rdi, 1
    mov     rsi, str1
    mov     rdx, 6  
    syscall
    mov     rax, 1
    mov     rdi, 1
    mov     rsi, str2
    mov     rdx, 6  
    syscall
    mov     rax, 60
    mov     rdi, 0 
    syscall
在我构建并执行此代码之后,我得到了以下结果:

$ nasm -f elf64 -o first.o first.asm 
$ ld -o first first.o 
$ ./first 
abcd\nefgh\n$ 

为什么要打印新行字符
\n

您需要在字符串周围使用“反引号”来支持转义序列:

str1: db `abcd\n`
str2: db `efgh\n`
参考:

3.4.2字符串:

用反引号括起来的字符串支持C样式的特殊转义 人物。”


另一种方法是将ASCII码0xA用于新行:

section .data
    str1: db "abcd", 0xA
    str2: db "efgh", 0xA