linux - ASM printf : no output if string doesn't include\n newline

标签 linux assembly x86 printf att

这段代码在屏幕上打印Hello

.data
    hello: .string "Hello\n"
    format: .string "%s" 
.text
    .global _start 
    _start:

    push $hello
    push $format
    call printf

    movl $1, %eax   #exit
    movl $0, %ebx
    int $0x80

但如果我从 hello 字符串中删除 '\n',如下所示:

.data
    hello: .string "Hello"
    format: .string "%s" 
.text
    .global _start 
    _start:

    push $hello
    push $format
    call printf

    movl $1, %eax   #exit
    movl $0, %ebx
    int $0x80

程序不工作。有什么建议吗?

最佳答案

退出系统调用(相当于 C 中的 _exit)不会刷新标准输出缓冲区。

输出换行符会导致行缓冲流上的刷新,如果它指向终端,则 stdout 将是。

如果你愿意在 libc 中调用 printf,你不应该对以同样的方式调用 exit 感到难过。在你的程序中有一个 int $0x80 并不会让你成为一个裸机坏蛋。

您至少需要在退出前push stdout;call fflush。或者push $0;call fflush。 (fflush(NULL) 刷新所有输出流)

关于linux - ASM printf : no output if string doesn't include\n newline,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19980518/

相关文章:

c - 指向函数名称、输入参数、?

c - x86 ADC 进位标志和长度

assembly - 8086 汇编问题,这段代码是做什么的

assembly - 第二阶段 bootLoader 未在 bochs、LINUX(ubuntu 16.04)、Brokenthorn osdev 系列中加载

assembly - 'h' 后缀是什么意思?

linux - 如何在 PF_UNIX 套接字的服务器端打印客户端 sun_paths 名称?

php - 尝试安装 Composer 时出现 SSL 证书错误

检查 TCP 套接字上的传入接口(interface)

c - C 中的内联汇编

c - 是否可以调用驻留在 exe 中的非导出函数?