加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux – 从程序集中读取文件

发布时间:2020-12-13 19:00:15 所属栏目:Linux 来源:网络整理
导读:我正在尝试在Linux环境中学习汇编 x86.我能找到的最有用的教程是Writing A Useful Program With NASM.我自己设置的任务很简单:读取文件并将其写入stdout. 这就是我所拥有的: section .text ; declaring our .text segment global _start ; telling where p

我正在尝试在Linux环境中学习汇编 – x86.我能找到的最有用的教程是Writing A Useful Program With NASM.我自己设置的任务很简单:读取文件并将其写入stdout.

这就是我所拥有的:

section  .text              ; declaring our .text segment
  global  _start            ; telling where program execution should start

_start:                     ; this is where code starts getting exec'ed

  ; get the filename in ebx
    pop   ebx               ; argc
    pop   ebx               ; argv[0]
    pop   ebx               ; the first real arg,a filename

  ; open the file
    mov   eax,5           ; open(
    mov   ecx,0           ;   read-only mode
    int   80h               ; );

  ; read the file
    mov     eax,3         ; read(
    mov     ebx,eax       ;   file_descriptor,mov     ecx,buf       ;   *buf,mov     edx,bufsize   ;   *bufsize
    int     80h             ; );

  ; write to STDOUT
    mov     eax,4         ; write(
    mov     ebx,1         ;   STDOUT,; mov     ecx,buf       ;   *buf
    int     80h             ; );

  ; exit
    mov   eax,1           ; exit(
    mov   ebx,0           ;   0
    int   80h               ; );

这里的一个关键问题是教程从未提及如何创建缓冲区,bufsize变量或者确实是变量.

我该怎么做呢?

(旁白:经过至少一个小时的搜索,我对学习装配的低质量资源感到震惊.当唯一的文件是在网上交易的传闻时,电脑怎么运行?)

最佳答案
你必须在bss部分和bufsize数据中声明你的缓冲区

section .data
   bufsize dw      1024

section .bss
   buf     resb    1024

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读