我正在尝试在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
原文地址:https://www.jb51.cc/linux/440109.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。