pgubook-readers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Pgubook-readers] pgubook with nasm assembler version


From: Bryn M. Reeves
Subject: Re: [Pgubook-readers] pgubook with nasm assembler version
Date: Thu, 14 Apr 2011 10:38:31 +0100
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.15) Gecko/20101027 Fedora/3.0.10-1.fc12 Thunderbird/3.0.10

On 04/14/2011 09:29 AM, address@hidden wrote:
> Dear all,
> 
> Could you please answer a question about memory addressing (the beginning of 
> book).
> 
> there's a text (Data Accessing methods, p. 15):
> "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."
> 
> I don't understand why to access the fourth word I need index 3 and 
> multiplier 4,
> I think I need index register 4 and multiplier 3. Because If I need just the 
> next word,

Index is 3 but counting from 0 so it's the _fourth_ location that you get to
when you apply the multiplier. This gets confusing because when someone says the
"fourth word" from some location they mean the word numbered 3 since the number
of the first word is 0.

Sometimes it's also easier to think of the address calculations as repeated
addition than multiplication.

In the first example the base address is 2002 and the multiplier is 1 (bytes).
With an index up to three we do:

base   i   m = addr
2002 + 0 * 1 = 2002
2002 + 1 * 1 = 2003
2002 + 2 * 1 = 2004
2002 + 3 * 1 = 2005 <<< [1]

> I need index register 4 and multiplier 1.
> Am I not right?

An index register of 4 and a multiplier of 1 (with the same base, 2002) would
give the first byte of the second word:

base + i * m = addr
2002 + 0 * 1 = 2002
2002 + 1 * 1 = 2003
2002 + 2 * 1 = 2004
2002 + 3 * 1 = 2005
2002 + 4 * 1 = 2006 <<< [2]

This size of a word is 4 (bytes). Again, counting begins at 0 so for the example
in the book we have:

base + i * m = addr
2002 + 0 * 4 = 2002
2002 + 1 * 4 = 2006
2002 + 2 * 4 = 2010
2002 + 3 * 4 = 2014 <<< [3]

To put this in a way that lets you see it all together consider this lame bit of
ascii-art:

 Addr  Off Word    Example
 2002  0   0 (1st)
       1
       2
_____  3           [1]
 2006  4   1 (2nd) [2]
       5
       6
_____  7
 2010  8   2 (3rd)
       9
      10
_____ 11
 2014 12   3 (4th) [3]
      13
      14
      15

Regards,
Bryn.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]