Linux 带气体组件的Printf
如果字符串末尾缺少Linux 带气体组件的Printf,linux,assembly,printf,x86-64,gnu-assembler,Linux,Assembly,Printf,X86 64,Gnu Assembler,如果字符串末尾缺少\n(LF-换行符),我不知道为什么不能在气体组件中使用printf打印任何内容。如果我将换行符\n放入行打印,但是如果我删除\n行不打印。有人能告诉我为什么吗 .extern printf .section .data hello: .string "Hello!" # doesn't print this way when \n is missing .section .text .globl _start _start: nop movl
\n
(LF-换行符),我不知道为什么不能在气体组件中使用printf
打印任何内容。如果我将换行符\n
放入行打印,但是如果我删除\n
行不打印。有人能告诉我为什么吗
.extern printf
.section .data
hello:
.string "Hello!" # doesn't print this way when \n is missing
.section .text
.globl _start
_start:
nop
movl $hello, %edi
movl $0, %eax
call printf
_end:
movq $60, %rax #use the _exit syscall
movq $0, %rdi #return error code 0
syscall #make syscall
pushl%ebp
lea你好,%edi
movl%esp,%ebp/*如果您希望使用C库(它是printf
的一部分),请使用main
作为入口点,不要使用exit
syscall。您没有让C库正确关闭,因此缓冲行不会被打印。注:下次如果你看到你的问题出现格式错误,请自己解决。根据需要使用预览。请尝试在要输出的字符串定义中使用.asciz
而不是.string
。很抱歉Jester没有达到您的高标准。使用正确的格式是一个非常低的标准。你确实看到了,对吗?可怜的zx485不得不帮你修好。你在寻求帮助,正确的发布是基本礼貌。Jistle是正确的,你应该考虑使用<代码>主< /代码>作为入口点,并链接到C运行时。然后可以使用ret
返回调用main(而不是exit
syscall)的C运行时,该运行时将正确刷新输出缓冲区,并退出程序。如果您坚持使用\u start
作为入口点,那么您应该调用退出
功能(通过调用退出
)。将返回代码放入%edi
。虽然此代码可以回答问题,但提供有关如何和/或为什么解决问题的附加上下文将提高答案的长期价值。
pushl %ebp
lea hello, %edi
movl %esp, %ebp /*<----*/
call printf
popl %ebp