linux – 从程序集中读取文件

前端之家收集整理的这篇文章主要介绍了linux – 从程序集中读取文件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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

这就是我所拥有的:

  1. section .text ; declaring our .text segment
  2. global _start ; telling where program execution should start
  3. _start: ; this is where code starts getting exec'ed
  4. ; get the filename in ebx
  5. pop ebx ; argc
  6. pop ebx ; argv[0]
  7. pop ebx ; the first real arg,a filename
  8. ; open the file
  9. mov eax,5 ; open(
  10. mov ecx,0 ; read-only mode
  11. int 80h ; );
  12. ; read the file
  13. mov eax,3 ; read(
  14. mov ebx,eax ; file_descriptor,mov ecx,buf ; *buf,mov edx,bufsize ; *bufsize
  15. int 80h ; );
  16. ; write to STDOUT
  17. mov eax,4 ; write(
  18. mov ebx,1 ; STDOUT,; mov ecx,buf ; *buf
  19. int 80h ; );
  20. ; exit
  21. mov eax,1 ; exit(
  22. mov ebx,0 ; 0
  23. int 80h ; );

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

我该怎么做呢?

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

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

  1. section .data
  2. bufsize dw 1024
  3. section .bss
  4. buf resb 1024

猜你在找的Linux相关文章