This is the code I have:
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
and I have a file called all.txt with contents:
61 62 63 0A 64 65 66 0A (abc - new line - def - new line)
Here is a sample run:
koray@koray-VirtualBox:~/asm/buffasm$ ./buff < all.txt
80koray@koray-VirtualBox:~/asm/buffasm$
So the first read of the code tries to read 1024 bytes from the file. The file itself has 8 bytes.. Then it prints 8 in the console which is fine I guess. But then, why does it print a '0' which means an end of file? I would expect it to read the same 8 bytes again? Why is it trying to read the next 1024 bytes?