7.2 Indirect Addressing of the CPU Memory Areas
Indirect addressing uses a pointer to access the data in memory. The S7-200 CPU allows you to use pointers to address the following memory areas indirectly: I, Q, V, M, S, T (current value only), and C (current value only). You cannot address individual bit or analog values indirectly.
Creating a Pointer
To address a location in memory indirectly, you must first create a pointer to that location. Pointers are double word memory locations that contain the address of another memory
location. You can only use V memory locations or accumulator registers (AC1, AC2, AC3) as pointers. To create a pointer, you must use the Move Double Word (MOVD) instruction to
move the address of the indirectly addressed memory location to the pointer location. The input operand of the instruction must be preceded with an ampersand (&) to signify that the
address of a memory location, instead of its contents, is to be moved into the location identified in the output operand of the instruction (the pointer).
Example: MOVD &VB100, VD204
MOVD &MB4, AC2
MOVD &C4, VD6
Note:If you want to access a word or double word value in the I, Q, V, M, or S memory areas indirectly, you must specify the address of the value’s initial byte as the input operand of the MOVD instruction used to create the pointer. For example, VB100 is the address of the initial byte of VW100, and MB4 is the address of the initial byte of MD4. If a symbol name was assigned to the word or double word value, then you cannot use that symbol name in the MOVD instruction used to create the pointer since the address of the value’s initial byte must be specified in the instruction’s input operand. You must assign a different symbol name to the address of the initial byte of the word or double word memory location for use in pointer creation under these circumstances.
Example: ‘‘Pump_Speed’’ assigned as the symbol name for VW100
‘‘Pump_Speed_IB’’ assigned as the symbol name for VB100
(which is the initial byte of the word value stored in VW100)
MOVD &‘‘Pump_Speed’’, AC1 illegal (&VW100 is not allowed)
MOVD &‘‘Pump_Speed_IB’’, AC1 correct (&VB100 is OK)
Using a Pointer to Access Data
Entering an asterisk (*) in front of an operand for an instruction specifies that the operand is a pointer. Using the example shown in Figure 7-9, *AC1 specifies that AC1 is a pointer to the word-length value being referenced by the Move Word (MOVW) instruction. In this example, the values stored in both V200 and V201 are moved to accumulator AC0.
Modifying Pointers
You can change the value of a pointer. Since pointers are 32-bit values, use double-word instructions to modify pointer values. Simple mathematical operations, such as adding or incrementing, can be used to modify pointer values. Remember to adjust for the size of the data that you are accessing:
1. When accessing bytes, increment the pointer value by one.
2. When accessing a word or a current value for a timer or counter, add or increment the pointer value by two.
3. When accessing a double word, add or increment the pointer value by four.
Figure 7-10 shows an example of how you can create an indirect address pointer, how data is accessed indirectly, and how you can increment the pointer.