如何使用 c 库函数以 Linux 汇编语言将文本文件的内容打印到 STDOUT?

How to print the content of a text file to STDOUT in Linux Assembly Language using c library functions?

首先,我尝试使用 fopen 函数打开一个文件并使用 fprint 函数打印文件内容,但它只是将一堆符号打印到终端。

一段时间后,我意识到它没有将指向流的指针作为参数,并且上述行为是预期的。 它正在打印实际的指针值。 putc 或 puts 函数似乎也没有将指向文件 I/O 流的指针作为参数。

我现在最好的猜测是我必须访问以某种方式创建的缓冲区 fopen 函数!但我不知道如何或是否可能。总而言之,我现在完全被困住了。

这里的最终目标是从STDIN获取输入and/or一个文件对文本做一些处理(例如:小写到大写)并将结果输出到STDOUT and/or 一个文件。我想如果我能够得到上述问题的答案,那么它应该有助于实现最终目标。

PS:让我知道是否可以通过任何方式改进问题。谢谢。

也许下面的代码有助于更好地理解我想说的内容。

.section .data
o_rdonly:
    .ascii "r"
content:
    .ascii "Content of the file: %d\n"  #This is how I figured what those random symbols were.

.section .bss
.lcomm buffer, 10

.section .text
.globl _start
_start:
    movl %esp, %ebp

    pushl $o_rdonly
    pushl 8(%ebp)
    call fopen

    ##Print the content of the file?##
    #pushl %eax #
    #call printf    #It just prints the actual address of the File I/O pointer.

    pushl [=11=]
    call exit

您需要先使用 freadfgets 或其他函数从文件中读取,然后将读取的内容写入标准输出。直接打印一个文件的内容没有快捷方式