Data Accessing in Programming

Data in computers is stored in specific locations much like a set of mail boxes each having their own address. For example: imagine a set of 16 mailboxes each with a number for its address and each containing data - a number.

Address

0

1

2

3

4

5

6

7

8

9

A

B

C

D

E

F

Data

F

0

E

A

2

9

B

1

3

5

7

9

2

4

6

8

Written 1999

Formatted 2010

 

Our mail man (microprocessor) can find the data in a selected box in various ways. The methods shown below are used by computers. The methods towards the bottom can be confusing even to experienced programmers, but they are needed for applications such as finding data in menus.

  1. Direct addressing - look into the box with a given address. For example, look for the data at address number 5, the data in the box is 9

    Address

    0

    1

    2

    3

    4

    5

    6

    7

    8

    9

    A

    B

    C

    D

    E

    F

    Data

    F

    0

    E

    A

    2

    9

    B

    1

    3

    5

    7

    9

    2

    4

    6

    8

  2. Indexed addressing - start at a box and count over from it certain number of boxes. For example what is in the box 3 places after box 5. Start at box 5 count over 3 - to box 8, take the data from box 8 which is 3.

    Address

    0

    1

    2

    3

    4

    5

    6

    7

    8

    9

    A

    B

    C

    D

    E

    F

    Data

    F

    0

    E

    A

    2

    9

    B

    1

    3

    5

    7

    9

    2

    4

    6

    8

  3. Indirect Addressing - look into a chosen box; use that number as the address of another box; take your data from that box. For example, find data indirectly from address B. Box B contains the number 9. 9 is the address of the box which contains your data. Box number 9 contain the number 5.

    Address

    0

    1

    2

    3

    4

    5

    6

    7

    8

    9

    A

    B

    C

    D

    E

    F

    Data

    F

    0

    E

    A

    2

    9

    B

    1

    3

    5

    7

    9

    2

    4

    6

    8

  4. Indirect with Indexing - look into a chosen box; count over from that box; that box holds an address go to that box to find data. For example: Address indirectly from box 1 with an index of 3. The box that is 3 places over from box 1 is box 4. Box 4 contains the address 2. Box 2 then holds the data E.

    Address

    0

    1

    2

    3

    4

    5

    6

    7

    8

    9

    A

    B

    C

    D

    E

    F

    Data

    F

    0

    E

    A

    2

    9

    B

    1

    3

    5

    7

    9

    2

    4

    6

    8

  5. Multiply Indirect with indexing - Go to a box, use that data as the address of another box. Count over from that box to another box and use its data as an address. Go to this new box a there find your data. For example: Indirectly look into box 4 and index with a 1: Look into box 4, it contains 2. Use 2 as your new address. Index from 2 over 1 that's box 3. Box 3 contains a new address (not your final data) which is A. Go to box A it contains 7. That is your data.

    Address

    0

    1

    2

    3

    4

    5

    6

    7

    8

    9

    A

    B

    C

    D

    E

    F

    Data

    F

    0

    E

    A

    2

    9

    B

    1

    3

    5

    7

    9

    2

    4

    6

    8

Although it may (or, in fact, "should") appear confusing, I used this multiply indirect addressing with indexes to create menus for my industrial controller project, because it creates efficient, concise, maintainable software.

 

Related pages at this site

 

Data Structures

A data structure is a pre-defined table of different types of data that can be used in different ways.

For example, in a menu (such as those that are available across the top of your computer screen) the data structure might contain the following for each item in the menu

  • a pointer to the labels to be displayed in the menu list eg for EDIT: CUT, COPY PASTE ...
  • a true/false sub-menu switch determining whether each item has a sub-menu
  • a true/false available option switch determining whether this option is currently available
  • a pointer telling the computer what to do if the user clicks on that item
  • a special requirements list - does this item function in a special way

For example, my project was a piece of equipment which had four push buttons and a display. I used a data structure and a data structure pointer. The data structure contained pointers which told the program how to change the pointer in response to a given button-push. It also contained pointers to tell the program where to find the data to display, and data type characteristics to tell the program how to display or modify the currently pointed data.

Side note: As I understand it, Object Oriented Programming (OOP) has replaced data structures since I wrote this. However, Objects work in manners quite similar to structures.
 

Return to: