# User-defined labels; Indirect addressing example (p. 60,61) Classic List Threaded 3 messages Open this post in threaded view
|

## User-defined labels; Indirect addressing example (p. 60,61)

 Q1. User-defined labels are introduced on page 60: ADD R2,R1,foo Whereas “ADD,R2, and R1” symbols may be provided by the Machine Language, the symbol “foo” is not. Shouldn’t there be a brief explanation of how “foo” comes to be recognized? Perhaps we will not be using such labels. Q2. Indirect addressing – array example (p.61) The book says: “the jth array entry should be physically located in a memory location that is at a displacement j from the array’s base address (assuming… that each array element uses a single word). Hence the address corresponding to the expression foo[j] can be easily calculated by adding the value of j to the value of foo.” This is confusing. No example is provided, so I made one: foo is at 1600. If the value of j is 0, foo = 1600 + (16 * j) (16 * 0) (0) = 1600. If the value of j is 1, foo = 1600 + (16 * j) (16 * 1) (16) = 1616. If the value of j is 2, foo = 1600 + (16 * j) (16 * 2) (32) = 1632. At this point, j + foo = (2 + 1600) = 1602, not 1632.   In foo[j], j is an index showing which 16-bit address (element of array) should be used. How can the index j also equal the displacement from the base address?
Open this post in threaded view
|

## Re: User-defined labels; Indirect addressing example (p. 60,61)

gs99 wrote
No example is provided, so I made one: foo is at 1600.
If the value of j is 0, foo = 1600 + (16 * j) (16 * 0) (0) = 1600.
If the value of j is 1, foo = 1600 + (16 * j) (16 * 1) (16) = 1616.
If the value of j is 2, foo = 1600 + (16 * j) (16 * 2) (32) = 1632.
At this point, j + foo = (2 + 1600) = 1602, not 1632.

In foo[j], j is an index showing which 16-bit address (element of array) should be used.
How can the index j also equal the displacement from the base address?
This section assumes that the size of foo's items is the same size as the memory's addressable cells, so
foo[j] = RAM[1600+j]

The * in this section has nothing to do with multiplication.

This is a case where a picture is worth a thousand words

1599
foo -->1600foo
1601foo
1602foo
1603

--Mark