在汇编中循环读取文件

时间:2017-05-07 16:35:35

标签: linux assembly

我应该写一个小型程序集" program"只需使用循环读取文件并将内容输出到STDOUT。

现在,我制作了一个可以读取文件的程序,不幸的是只输出了第一行。我也无法弄清楚如何使用循环。

这是我第一次使用装配工作而且我这样做是因为我必须这样做,而不是因为我想要。

这是我的代码:

section .text
   global _start         ;must be declared for using gcc

_start:                  ;tell linker entry point
   ;open the file for reading
   mov eax, 5
   mov ebx, file_name
   mov ecx, 0             ;for read only access
   mov edx, 0777          ;read, write and execute by all
   int  0x80

   mov  [fd_in], eax

   ;read from file
   mov eax, 3
   mov ebx, [fd_in]
   mov ecx, info
   mov edx, 26
   int 0x80

   ; close the file
   mov eax, 6
   mov ebx, [fd_in]

   ; print the info 
   mov eax, 4
   mov ebx, 1
   mov ecx, info
   mov edx, 26
   int 0x80

   mov  eax,1             ;system call number (sys_exit)
   int  0x80              ;call kernel

section .data
file_name db './passwd'

section .bss
fd_out resb 1
fd_in  resb 1
info resb  26

0 个答案:

没有答案
相关问题