Hi !

Yes ! That's what I wanted to know :-)

Thank you
Date: Thu, 22 May 2008 23:05:50 -0700
From: [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Subject: Re: [Pgubook-readers] Chapter 5, toupper-program: understanding the 
read loop
CC: [email protected]

Hello,

If I understand you correctly, you are asking why isn't the same N (buffer 
size) bytes of the file read over an over again, because there is no explicit 
"move the file position pointer forward" in the program.


This is handled "under the covers" by the Linux system call "read."

.equ SYS_READ, 3

>From the documentation:

read()

attempts to read up to
count

bytes from file descriptor
fd

into the buffer starting at
buf.

"

On success, the number of bytes read is returned (zero indicates end of
file), and the file position is advanced by this number."

http://linux.about.com/od/commands/l/blcmdl2_read.htm

Justis


On Sat, May 17, 2008 at 6:10 AM, david helfgott <[EMAIL PROTECTED]> wrote:






Hi there !

I got some serious problems with understanding the read loop in the toupper 
programm.

Where does the computer know to start again from, after the "jmp read_loop 
begin" ?

Why doesn't the computer always reads the same first 500 bytes into the buffer ?


Where does he knows from, where he has to continue ?

after the "jmp read_loop begin" he starts again at

movl $SYS_READ, %eax
movl $ST_FD_IN(%ebp), %ebx
movl $BUFFER_DATA, %ecx
movl $BUFFER_SIZE, %edx

int $LINUX_SYSCALL

that's exactly the same information he got in the first place. 

So if I have a file conatining 700 bytes.
Where does he know from to start reading at byte No. 501 in the secon run, and 
not just read the first 500 bytes again ?


Where's the extra information, that tells him, he already red the first 500 
bytes and has to read the next 500 byte ?





####################

read_loop_begin:

###READ IN A BLOCK FROM THE INPUT FILE### 


movl $SYS_READ, %eax 


#get the input file descriptor 

movl ST_FD_IN(%ebp), %ebx 


#the location to read into 

movl $BUFFER_DATA, %ecx 


#the size of the buffer 
movl $BUFFER_SIZE, %edx 



#Size of buffer read is returned in %eax 

int $LINUX_SYSCALL 


###EXIT IF WE'VE REACHED THE END### 
#check for end of file marker 

cmpl $END_OF_FILE, %eax 


#if found or on error, go to the end 


jle end_loop 


continue_read_loop: 
###CONVERT THE BLOCK TO UPPER CASE### 

pushl $BUFFER_DATA #location of buffer 
pushl %eax #size of the buffer 
call convert_to_upper 
popl %eax #get the size back 

addl $4, %esp #restore %esp 



###WRITE THE BLOCK OUT TO THE OUTPUT FILE### 
#size of the buffer 

movl %eax, %edx 
movl $SYS_WRITE, %eax 

#file to use 
movl ST_FD_OUT(%ebp), %ebx 


#location of the buffer 

movl $BUFFER_DATA, %ecx 
int $LINUX_SYSCALL 


###CONTINUE THE LOOP### 
jmp read_loop_begin 
end_loop: 


###CLOSE THE FILES### 
#NOTE - we don't need to do error checking 

# on these, because error conditions 
# don't signify anything special here 
movl $SYS_CLOSE, %eax 
movl ST_FD_OUT(%ebp), %ebx 
int $LINUX_SYSCALL 
movl $SYS_CLOSE, %eax 
movl ST_FD_IN(%ebp), %ebx 
int $LINUX_SYSCALL 

###EXIT### 
movl $SYS_EXIT, %eax 
movl $0, %ebx 
int $LINUX_SYSCALL 

#######################

Windows Live Messenger - Schreiben. Sehen. Hören. Wie im echten Leben. Windows 
Live Messenger!


_______________________________________________

Pgubook-readers mailing list

[email protected]

http://lists.nongnu.org/mailman/listinfo/pgubook-readers





_________________________________________________________________
Völlige Gestaltungsfreiheit: Mit Live.com können Sie Ihre Homepage genau so 
gestalten, wie Sie es möchten.
http://www.live.com/getstarted
_______________________________________________
Pgubook-readers mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/pgubook-readers

Reply via email to