이것은 내가 가지고있는 코드 :이 어셈블리 코드가 같은 바이트를 다시 읽지 않고 대신 파일의 끝을 반환하는 이유는 무엇입니까?
section .bss
bufflen equ 1024
buff: resb bufflen
whatread: resb 8
section .data
section .text
global main
main:
nop
read:
mov eax,3 ; Specify sys_read
mov ebx,0 ; Specify standard input
mov ecx,buff ; Where to read to...
mov edx,bufflen ; How long to read
int 80h ; Tell linux to do its magic
; Eax currently has the return value from linux system call..
add eax, 30h ; Convert number to ASCII digit
mov [whatread],eax ; Store how many byte reads info to memory at loc whatread
mov eax,4 ; Specify sys_write
mov ebx,1 ; Specify standart output
mov ecx,whatread ; Get the address of whatread in ecx
mov edx,4 ; number of bytes to be written
int 80h ; Tell linux to do its work
mov eax,3 ; Specify sys_read
mov ebx,0 ; Specify standard input
mov ecx,buff ; Where to read to...
mov edx,bufflen ; How long to read
int 80h ; Tell linux to do its magic
; Eax currently has the return value from linux system call..
add eax, 30h ; Convert number to ASCII digit
mov [whatread],eax ; Store how many byte reads info to memory at loc whatread
mov eax,4 ; Specify sys_write
mov ebx,1 ; Specify standart output
mov ecx,whatread ; Get the address of whatread in ecx
mov edx,4 ; number of bytes to be written
int 80h ; Tell linux to do its work
mov eax, 1;
mov ebx, 0;
int 80h
나는 내용으로 all.txt 라는 파일이 있습니다
[email protected]:~/asm/buffasm$ ./buff < all.txt
[email protected]:~/asm/buffasm$
: 여기
61 62 63 0A 64 65 66 0A (abc - new line - def - new line)
이 샘플 실행을 그래서 코드의 첫 번째 읽기는 파일에서 1024 바이트를 읽으려고합니다. 파일 자체에는 8 바이트가 있습니다. 콘솔에서 8을 인쇄합니다. 그런데 왜 파일 끝을 의미하는 '0'이 인쇄됩니까? 같은 8 바이트를 다시 읽으 리라고 기대합니까? 왜 다음 1024 바이트를 읽으려고합니까?
왜 다시 읽습니까? 파일 끝을 치고 파일 포인터를 다시 설정하지 않았습니다. 파일에서 현재 위치에 대한 개념을 알지? 그것은 흉자에 특정한 것이 아닙니다. – Jester
@Jester 파일 포인터는 어디에 보관합니까? 내가 아는 한 똑같은 파일을 다시 전달할 것이며이 사실을 알아서는 안됩니다. 포인터를 어떻게 재설정 할 수 있습니까? –
@Jester 또한 왜 9th 바이트로 첫 번째 시도에서 EOF를 읽지 않습니까? –