Direct and Indirect Addressing

When you write your program, you can use either of two modes of addressing instruction operands: direct or indirect.

Direct Addressing

Direct addressing specifies the memory area, size, and location; for example, VW790 refers to word location 790 in V memory area.

You can access several PLC memory areas (V, I, Q, M, and SM) as bytes, words, or double words. To specify whether an address is to be accessed as a byte, word, or double word, use the size designator following the memory area. For example, to access V100 as a byte, use VB100 to indicate this; as a double word, use VD100.

To access a bit in a memory area, specify the memory area, the byte address, and the bit number preceded by a period. Your notation would follow this format: VB100.7. The example accesses the last bit in byte V100.

Indirect Addressing

You can address indirectly the data types I, Q, M, T, C, and V. To do this, create a pointer to the location.

All pointers are double word values, and you can use them to access byte, word, and double word values. You cannot indirectly address bit values.

Use a Move Double Word (MOVD) instruction to move the address of a location (pointer) to the desired destination. Use only V memory locations or accumulator registers AC1, AC2, and AC3 as the destination address.

Place an ampersand (&) at the beginning of the pointer address.

Use an asterisk (*) before the destination address to indicate that the address contained in this location is to be used instead of the value.

You can use indirect notation for symbols as well as for memory addresses. For instance, if the symbolic name for VB200 is Example, then these instructions are both valid:
MOVD &VB200, AC1

MOVD &Example, AC1

In the example below, a pointer to VB200 is created, the value is accessed, and the pointer is incremented.

Guidelines for Incrementing/Decrementing Pointers

ĚTo access bytes indirectly, increment or decrement the pointer by one.

ĚTo access words indirectly, increment or decrement the pointer by two.

ĚTo access double words indirectly, increment or decrement the pointer by four. If you increment a double word from a starting location that causes the ending location to be out-of-range of the upper V-memory boundary, you receive a run-time error when the program executes.

ĚTo access timer or counter current values (which are word values), increment or decrement the pointer by two.

See Also:

Addressing Overview (GS 2.2)

Symbol Table/ Global Variable Table