That's very strange, I copied and pasted your program, assembled it and linked it and when i did 'echo $?' the result was 62.
On 07/11/15 17:00, [email protected] wrote: > Send Pgubook-readers mailing list submissions to > [email protected] > > To subscribe or unsubscribe via the World Wide Web, visit > https://lists.nongnu.org/mailman/listinfo/pgubook-readers or, via > email, send a message with subject or body 'help' to > [email protected] > > You can reach the person managing the list at > [email protected] > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Pgubook-readers digest..." > > > Today's Topics: > > 1. ending-address using base pointer addressing mode (William > Rodrigues) 2. Re: ending-address using base pointer addressing > mode (Roger) > > > ---------------------------------------------------------------------- > > > Message: 1 Date: Fri, 6 Nov 2015 21:36:56 -0200 From: William > Rodrigues <[email protected]> To: [email protected] > Subject: [Pgubook-readers] ending-address using base pointer > addressing mode Message-ID: > <CAMxh6gWxY1mocBDu4pK1UsB2-Sfa3Xz4u_gdk++b_ccgF=g...@mail.gmail.com> > > > Content-Type: text/plain; charset="utf-8" > > Hi everyone, I'm William from Brazil; this is my first > participation on here. I am reading the 4th chapter from pgubook, > but at one exercise of the third I'm at some difficulty. The text > says to modify the maximum.s code and use an ending address rather > than the number 0 to know when to stop. > > I tried this, > > .section .data > > data_items: .long 3,62,14,20,35,49,74,55,0 > > .section .text .globl _start _start: movl $data_items, %ecx # > initialize %ecx with the address of data_items movl 4(%ecx), %ebx # > go to base pointer addressing mode, trying to get the value 62. > movl $1, %eax int $0x80 > > If %ecx has the (pointer) address of data_items. So, why the > return value was 0 instead of 62 or 35? > > Thanks. -------------- next part -------------- An HTML attachment > was scrubbed... URL: > <http://lists.nongnu.org/archive/html/pgubook-readers/attachments/20151106/3ff1ff36/attachment.html> > > > ------------------------------ > > Message: 2 Date: Fri, 6 Nov 2015 21:53:07 -0500 From: Roger > <[email protected]> To: [email protected] Subject: > Re: [Pgubook-readers] ending-address using base pointer addressing > mode Message-ID: <[email protected]> > Content-Type: text/plain; charset=us-ascii > >> On Fri, Nov 06, 2015 at 09:36:56PM -0200, William Rodrigues >> wrote: Hi everyone, I'm William from Brazil; this is my first >> participation on here. I am reading the 4th chapter from >> pgubook, but at one exercise of the third I'm at some difficulty. >> The text says to modify the maximum.s code and use an ending >> address rather than the number 0 to know when to stop. >> >> I tried this, **.section .data >> >> data_items: ** .long 3,62,14,20,35,49,74,55,0 >> >> **.section .text **.globl _start _start: ** movl $data_items, >> %ecx******** # initialize %ecx with the address of data_items ** >> movl 4(%ecx), %ebx******************** # go to base pointer >> addressing mode, trying to get the value 62. ** movl $1, %eax ** >> int $0x80 >> >> If %ecx has the (pointer) address of data_items. So, why the >> return value was 0 instead of 62 or 35? Thanks. > > If I'm not mistaken, there are some minor mistakes within the > book, or code sections. Typos I think. You can either trace the > code to find the error (as I did when I first read the book a > decade ago), or search using Google to find the specific errors > mentioned by others. > > It is possible somebody has already compiled an errata listing by > now for this book! > > Still, it is a great book, or great read, and you will not regret > reading, nor doing/performing each of the exercises as I have. Most > programmers take little time to understand how using their C/C++ > routines use or effect the CPU. On the flip, these programmers > publish code by the handful on a daily basis. > _______________________________________________ Pgubook-readers mailing list [email protected] https://lists.nongnu.org/mailman/listinfo/pgubook-readers
