Printing - Direct and Indirect Addressing
Printing - Direct and Indirect Addressing
When you write your program, you can use either of three modes of addressing instruction operands:
• Direct
• Symbolic
• Indirect
Direct Addressing
The S7-200 stores information in different memory locations that have unique addresses. You can explicitly identify the
memory address that you want to access. This allows your program to have direct access to the information. Direct addressing
specifies the memory area, size, and location; for example, VW790 refers to word location 790 in V memory area.
To access a bit in a memory area, you specify the address, which includes the memory area identifier, the byte address, and
the bit number preceded by a period. The figure below shows an example of accessing a bit (which is also called "byte.bit"
addressing). In this example, the memory area and byte address (I = input, and 3 = byte 3) are followed by a period (".") to
separate the bit address (bit 4).
You can access data in most memory areas (V, I, Q, M, S, L, and SM) as bytes, words, or double words by using the
byte-address format. To access a byte, word, or double word of data in the memory, you must specify the address in a way
similar to specifying the address for a bit. This includes an area identifier, data size designation, and the starting byte address
of the byte, word, or double-word value, as shown in the figure below.
Data in other memory areas (such as T, C, HC, and the accumulators) are accessed by using an address format that includes
an area identifier and a device number.
Symbolic Addressing
Symbolic addressing uses a combination of alphanumeric characters to identify an address. A symbolic constant uses a
symbol name to identify a constant number or ASCII character value.
For SIMATIC programs, you make global symbol assignments by using the symbol table. For IEC programs, you make global
symbol assignments by using the global variable table. If you have assigned symbolic addresses in the SIMATIC Symbol Table
or a Local Variable Table, you can toggle to switch between viewing parameter addresses with Absolute (for example, I0.0) or
Symbolic (for example, Pump1) representation.
The Symbolic Addressing feature is controlled from the View menu. A checkmark next to the name means that the feature is
turned on. Otherwise, all addresses are displayed as absolute addresses only.
Tip:
If you use the same name for an address at the local and global level, the local use takes
precedence. In other words, if the program editor finds a definition for the name in the local
variable table for a given program block, that definition is used. If no definition is found, the
program editor then checks the symbol table.
For example: You define PumpOn as a global symbol. You also define it as a local variable
in SBR2, but not SBR1. When the program is compiled, the local definition is used for
PumpOn in SBR2; the global definition is used for PumpOn in SBR1.
Indirect Addressing
Indirect addressing uses a pointer to access the data in memory. Pointers are double word memory locations that contain the
address of another memory location. You can only use V memory locations, L memory locations, or accumulator registers
(AC1, AC2, AC3) as pointers. To create a pointer, you must use the Move Double Word instruction to move the address of the
indirectly addressed memory location to the pointer location. Pointers can also be passed to a subroutine as a parameter.
The S7-200 allows pointers to access the following memory areas: I, Q, V, M, S, T (current value only), and C (current value
only). You cannot use indirect addressing to access an individual bit or to access AI, AQ, HC, SM, or L memory areas.
To indirectly access the data in a memory address, you create a pointer to that location by entering an ampersand (&) and the
memory location to be addressed. 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).
Entering an asterisk (*) in front of an operand for an instruction specifies that the operand is a pointer. As shown in the figure
below, entering *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 VB200 and VB201 are moved to accumulator AC0.
As shown in the figure below, 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.
Tip:
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)
Memory Types and Properties
CPU Memory Address Ranges
Special Memory Addresses
Symbol Table/ Global Variable Table