Addressing Modes of Siemens S7 Series PLC (1)

The term "addressing mode" refers to the CPU's method of locating the physical address corresponding to the variable address in the program. The Siemens S7 series PLC supports various addressing modes, providing considerable flexibility for program development. In this article, we will discuss how the S7 series PLC (300/400/1200/1500) performs addressing.

The addressing modes of the S7 series PLC can be categorized into direct addressing and indirect addressing.

Direct addressing refers to accessing the CPU's memory directly within the program. The memory areas involved include Input/Output image area (I/O), bit storage area (M), timers (T), counters (C), data blocks (DB), and function blocks (FB/FC), among others. Direct addressing can further be classified into absolute addressing and symbolic addressing.

Absolute addressing involves using the physical address of the memory area in the program. For example: I0.0, Q1.0, M2.0, and so on.

The physical address alone does not convey its meaning intuitively. For instance, seeing "I 1.0" in the program doesn't indicate which button's input it represents or which proximity switch's input it is. This addressing method hinders program readability, writing, and later maintenance. To enhance program readability and maintainability, symbolic addressing is employed.

Symbolic addressing involves assigning a symbol (name) related to the function to the physical address. In the previous example of "I 1.0," we assign the symbol "Start ON" to it, making it clear that it represents the power-on button. Symbolic addressing supports all memory areas (I, O, M, C, T, DB, L), enhancing program readability and maintainability, making it a common addressing method in large program development.

Both of the aforementioned addressing modes fall under direct addressing. In advanced program development, another type of addressing comes into play: indirect addressing.

Indirect addressing is accomplished using pointers or address registers, allowing dynamic modification of instruction addresses during program execution by changing the pointer or address register values. Indirect addressing involves 16-bit and 32-bit pointers, addressing modes include memory indirect addressing and register indirect addressing. It offers powerful functionality but can pose some difficulty for beginners to comprehend. This article will initially focus on memory indirect addressing.

Memory indirect addressing utilizes 16-bit and 32-bit pointers. The 16-bit address pointer is used for addressing timers (T), counters (C), program blocks (FB/FC), and data blocks (DB). It accesses data in word format, with the 16-bit pointer acting as an unsigned number (0 to 65535), representing the corresponding memory's identifier.

Addressing format: Area Identifier [16-bit Address Pointer];

For example: Decrement Counter Instruction CD C[MW20]; "C" is the counter area identifier, and "MW20" represents the address pointer. Let's examine the following code snippet:


Here, MW22 is utilized as a 16-bit address pointer with a value of 20, designating the delayed timer as T20.

32-bit pointers enable addressing of memory at the bit, byte, word, and double-word levels. A 32-bit pointer, treated as a double-word, has its 0 to 2 bits indicating the bit address, bits 3 to 18 specifying the byte address, and bits 19 to 31 left undefined.

A 32-bit memory pointer is exclusively employed for internal area addressing, with the format: Area Identifier [32-bit Address Pointer];

When using a 32-bit pointer to access a byte, word, or double-word in memory, the bit address of the pointer needs to be set to 0. For instance: P#Q10.0. Let's examine the following code snippet:


In the example above, QB6 is accessed using a pointer. First, the pointer constant P#6.0 is stored in MD30. Then, the instruction "L QB[MD30]" loads the value of QB6 into Accumulator 1, which is subsequently transferred to the variable MB100. It's worth noting that "p32_1" is the symbolic name for MD30.

The following code snippet employs 32-bit pointers for bit manipulation:

Using MD34 as a 32-bit pointer, storing the constant P#2.5. When "I 2.5" is "1", Q10.1 becomes "1".

That concludes the introduction to direct addressing and memory indirect addressing for Siemens S7 series PLC. In subsequent articles, we will delve into register indirect addressing.