我设法构建了用于处理文件的NASM教程代码。它将文件的内容输出到stdout中,但是当我尝试访问数据缓冲区时,它只包含零。例如,在中间循环下面的代码中,EBX始终设置为0,当它包含文件字节时。nasm中的文件读取缓冲区为空
section .data
bufsize dw 1024
section .bss
buf resb 1024
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 ;);
mov ecx, 20
loop:
mov eax, 20
sub eax, ecx
mov ebx, [buf+eax*4]
loop loop
; 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 ;);
伟大的评论风格! – divinci