printf的无装配换行符 [英] Printf without newline in assembly

查看:131
本文介绍了printf的无装配换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近读到这篇文章的汇编用printf和scanf:

I've recently read this article on using printf and scanf in assembly:

intfmt的含义:DB"%D&QUOT ;, 10,0组装

在特别它说
在printf的,换行打印一个换行符,然后(如果输出是行缓冲模式下,它有可能是),刷新内部输出缓冲区,所以你可以看到的结果。所以,当你取下10,没有冲水你没有看到输出。

In particular it says "In printf, the newline prints a newline and then (if the output is in line buffered mode, which it probably is), flushes the internal output buffer so you can actually see the result. So when you remove the 10, there's no flush and you don't see the output."

不过,我不知道该怎么做,如果我不希望我在我的汇编文件后输出一个换行符。
下面是我写尝试打印而不换行一个简单的测试文件:

However I do not know what to do if I do not want a newline after my output in my assembly file. Here's a simple test file I've written to try printing without a newline:

extern printf


LINUX        equ     80H      ; interupt number for entering Linux kernel
EXIT         equ     60       ; Linux system call 1 i.e. exit ()




section .data
    int_output_format: db "%ld", 0


segment .text
    global  main


main:
    mov r8, 10
    push rdi
    push rsi
    push r10
    push r9
    mov rsi, r8
    mov rdi, int_output_format
    xor rax, rax
    call printf
    pop r9
    pop r10
    pop rsi
    pop rdi
    call os_return      ; return to operating system


os_return:
    mov  rax, EXIT      ; Linux system call 1 i.e. exit ()
    mov  rdi, 0     ; Error code 0 i.e. no errors
    syscall     ; Interrupt Linux kernel 64-bit

但文章我读过暗示stdout不是被刷新。我在想,也许我需要我的输出数后以某种方式刷新?但我真的不知道。

but as the article I've read suggests stdout isn't being flushed. I was thinking perhaps I need to somehow flush after I output the number? But I'm really not sure.

我使用NASM汇编语言。

I am using the NASM assembly language.

在此先感谢!

推荐答案

我的问题的正确答案是BasileStarynkevitch的意见建议之上。
我需要添加到我的code:

The correct answer for my question is as BasileStarynkevitch suggests in a comment above. I needed to add into my code:

extern fflush
...
xor rax, rax
call fflush
...

这篇关于printf的无装配换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆