【发布时间】:2011-10-07 20:57:41
【问题描述】:
我设法构建了一个 NASM 教程代码来处理文件。它将文件的内容输出到标准输出就好了,但是当我尝试访问数据缓冲区时,它只包含零。例如在下面的中间循环代码中,EBX 总是设置为 0,当它应该包含文件字节时。
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 ; );
【问题讨论】: