Herbert & Brian,

You should NOT think about indexed addressing in terms of records.
Records are typically buffered one at a time and not addressed by indexing.

It is better to see indexed addressing in terms of accessing arrays.
Say you have an array of 20 integers in memory.
(One integer = 4 bytes)
Now you can acces these in a loop, by using an index and the fixed
multiplier of 4 (4 bytes is the size of one element of the array).

so 1st element: index = 0 in %edi, address with "start_array (,%edi,4)"
next element: increment %edi and use same statement ("start_array(,%edi,4)")
etc.

When you have an array of characters (1 byte) then your multiplier is 1.

Hope this clarifies, if not, do not worry about it, it will become clearer
later in the book, just carry on!

success

GijsH







On Sun, Mar 7, 2010 at 12:46 PM, Herbert R Coburn <[email protected]>wrote:

> On 03/06/2010 11:04 PM, Brian Haag wrote:
>
>> Thanks very much for the response!  I think I follow you, but it doesn't
>> appear to be what the book says... but I think maybe the text of the
>> book is just unclear on this point.
>>
>>    Here is a sample record that starts at 2002 (I'm in the USA)
>>      Name: 30 bytes -- starts at 0
>>      Addr: 30 bytes -- starts at 30
>>      City: 25 bytes -- starts at 60
>>      State: 2 bytes -- starts at 85
>>      Zip:   9 bytes -- starts at 87
>>      Phone: 10 bytes -- starts at 96
>>
>>    Record Length is 106.
>>
>>    To find the City for the 7th record:
>>      I want to skip 6 records so the multiplier is 6.
>>      Each record is 106 bytes long, so the index is 106.
>>      The City field starts at the 60th byte, so add 60 to the address.
>>    Ergo, use (2002+60) for the address, 106 as the index, and (7-1) as
>>    the multiplier. That's 2062, 106, 6.
>>    <http://lists.nongnu.org/mailman/listinfo/pgubook-readers>
>>
>>
>> p 15 of the book is stating that I have three quantities to work with:
>> an address, an index register, and a multiplier:
>>
>> "For example, we could specify address 2002 and an index register. If
>> the index register contains the number 4, the actual address the data is
>> loaded from would be 2006. This way, if you have a set of numbers
>> starting at location 2002, you can cycle between each of them using an
>> index register."
>>
>> What does "cycle" mean here?  That I can increment the index register
>> and get a different byte every time I access memory using this method?
>>  Is this a different use than the one you described?  If the length of
>> a record is 1 byte, then I think you'd prescribe leaving the index
>> register at 1 and incrementing the multiplier, right?
>>
>> "On x86 processors, you can also specify a multiplier for the index.
>> This allows you to access memory a byte at a time or a word at a time (4
>> bytes). If you are accessing an entire word, your index will need to
>> be multiplied by 4 to get the exact location of the fourth element from
>> your address.  For example, if you wanted to access the fourth byte from
>> location 2002, you would load your index register with 3 (remember, we
>> start counting at 0) and set the multiplier to 1 since you are going a
>> byte at a time. This would get you
>> location 2005. However, if you wanted to access the fourth word from
>> location 2002, you would load your index register with 3 and set the
>> multiplier to 4. This would load from location 2014 - the fourth word."
>>
>> This is what confuses me.  I start with an address of 2002, an index of
>> 3, and a multiplier of 1.  This gets me location 2005.  The text (to me)
>> reads as "set the multiplier to the length of the record" ("a byte at a
>> time").
>>
>> See my confusion?  Thanks.
>>
>>
>>
>>  Cycle means loop through, incrementing the index register according to
> the what you quoted; incrementing the multiplier according to what I
> wrote.
>
> Now, I'm confused. Am I possibly wrong? Someone else will need to
> clarify.
>
>
> /herbc
>
>
>
>
> _______________________________________________
> Pgubook-readers mailing list
> [email protected]
> http://lists.nongnu.org/mailman/listinfo/pgubook-readers
>
_______________________________________________
Pgubook-readers mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/pgubook-readers

Reply via email to