[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Pgubook-readers] Chapter 5, toupper-program: understanding the read
From: |
roger |
Subject: |
Re: [Pgubook-readers] Chapter 5, toupper-program: understanding the read loop |
Date: |
Sat, 17 May 2008 20:32:41 -0800 |
I believe this is a known bug for this part of the book.
It's simple to fix once you understand the bug. ;-)
If you check the archives, you'll find the answer. Maybe another poster
remembers the specifics for this program.
On Sat, 2008-05-17 at 13:10 +0000, david helfgott 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
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/pgubook-readers
--
Roger
http://www.eskimo.com/~roger/index.html
signature.asc
Description: This is a digitally signed message part
- [Pgubook-readers] Chapter 5, toupper-program: understanding the read loop, david helfgott, 2008/05/17
- Re: [Pgubook-readers] Chapter 5, toupper-program: understanding the read loop,
roger <=
- Message not available
- RE: [Pgubook-readers] Chapter 5, toupper-program: understanding the read loop, roger, 2008/05/20
- Re: [Pgubook-readers] Chapter 5, toupper-program: understanding the read loop, Ben Schaffhausen, 2008/05/20
- Re: [Pgubook-readers] Chapter 5, toupper-program: understanding the read loop, roger, 2008/05/21
- Re: [Pgubook-readers] Chapter 5, toupper-program: understanding the read loop, roger, 2008/05/21
- Message not available
- RE: [Pgubook-readers] Chapter 5, toupper-program: understanding the read loop, roger, 2008/05/22
Re: [Pgubook-readers] Chapter 5, toupper-program: understanding the read loop, Justis Durkee, 2008/05/23