我設法構建了用於處理文件的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