|
From: | Herbert R Coburn |
Subject: | Re: [Pgubook-readers] Re: index register multiplier q |
Date: | Sat, 06 Mar 2010 20:36:57 -0800 |
User-agent: | Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.8) Gecko/20100227 Lightning/1.0b1 Thunderbird/3.0.3 |
On 03/05/2010 11:34 PM, Brian Haag wrote:
Whoops, this is for the example on page 15... I sent this once without being subscribed, and somehow messed up the copy/paste. On Fri, Mar 5, 2010 at 4:11 PM, Brian Haag <address@hidden <mailto:address@hidden>> wrote: re: indexed addressing mode In the example given, we specify address 2002 with 4 in the index register, giving us 2006 (the start of the second word). For x86 processors we can use a multiplier, so putting 3 in the index register with a multiplier of 1 would get us the contents of address 2005. However, the next example is a 3 in the index register with a multiplier of 4, resulting in reading from address 2014, the start of the fourth word. Now, it's easy enough to see that 2002 + (3 x 1) = 2005, and 2002 + (3 x 4) = 2014. What seems weird to me is that the multiplier determines WHERE in the word I end up reading. 1 gets me the fourth byte, 2 the third, 3 the second, and 4 the first. Am I thinking about this correctly? Am I wrong to think it's a little weird? Thanks, if anyone's actually listening. :)
No. Words are not part of the equation, assuming you mean the CPU's native word-size. The address is the beginning of the data structure + the offset into the first record. The index is the length of the record. The multiplier is which record, less one, you want to read from. 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. /herbc
[Prev in Thread] | Current Thread | [Next in Thread] |