direct addressing
It directly specifies the exact address to which the instruction operates. For example, in AQ10.0, Q10.0 is the address that instruction A directly operates on.
Therefore, indirect addressing, on the other hand, indirectly indicates the exact address of the instruction. For example, in AQ[MD10], the address is not given directly, but indirectly through the memory address MD10.
Types of indirect addressing
Indirect addressing can be divided into two main types: memory indirect addressing and register indirect addressing, as shown in Figure 1.
Figure 1 Addressing Mode
Memory indirect addressing
The address format for indirect memory addressing is: address identifier + pointer. The value contained in the memory cell pointed to by the pointer is the exact numerical unit of the address.
Memory indirect addressing has two pointer formats:
16-bit pointer:
A 16-bit address pointer is used for addressing timers, counters, and program blocks (DB, FC, FB). The 16-bit pointer is treated as an unsigned integer (0-65535) representing the number of a timer (T), counter (C), data block (DB, DI), or program block (FB, FC). The format of a 16-bit pointer is as follows:
Figure 216 pointer format
32-bit pointer:
A 32-bit address pointer is used for addressing bits, bytes, words, and double words in memory such as I, Q, M, L, and data blocks. A 32-bit address pointer can be represented by a double word. Bits 0 to 2 are used as the bit address for the addressing operation, bits 3 to 18 are used as the byte address for the addressing operation, and bits 19 to 31 are undefined. The format of a 32-bit pointer is as follows:
Figure 332-bit pointer format
Register indirect addressing
Register indirect addressing uses the CPU's address registers AR1 and AR2 for addressing. Both AR1 and AR2 are 32-bit registers, and register indirect addressing uses only 32-bit pointers.
It is divided into internal area indirect addressing and cross area addressing.
Indirect addressing of internal region registers
The pointer format is the same as that of a 32-bit pointer for memory indirect addressing. Bits 0 to 2 are used as the bit address for the addressing operation, bits 3 to 18 are used as the byte address for the addressing operation, and bits 19 to 31 are undefined. The format of a 32-bit pointer is as follows:
Figure 4 Internal Region 32-bit Pointer
Cross-region register indirect addressing
A pointer that contains information about a memory region is called a cross region pointer.
Similarly, the cross region pointer is 32 bits, and register indirect addressing requires the use of address register AR1 or AR2.
A 32-bit interleaved region pointer, with bits 0-18 having the same format as a 32-bit internal region pointer from the left; bits 19-23 and 27-20 are undefined.
Bit 31 is the cross region pointer identifier.
Bits 24-26 are memory region address identifiers; eight combinations represent eight different memory regions.
000 indicates no address range, for example, P#12.0;
001 represents the input address range I, for example, P#I12.0;
010 represents the output address area Q, for example, P#Q12.0;
011 represents the flag address area M, for example, P#M12.0;
100 represents data within a data block (DB), for example, P#DB1.DBX12.0
101 represents data in a data block (DI), for example, P#DI1.DIX12.0
110 represents the address range L, for example, P#L12.0;
111 represents the region address V of the calling program block, for example, P#V12.0;
The cross region pointer format is as follows:
P# pointers and Any pointers
P# pointer
POINTER is a parameter data type with a length of 6 bytes used to pass pointers. It is used to pass actual arguments of complex data types (such as ARRAY, STRUCT, and DT) to the called function FC and function block FB. The memory of the actual arguments can be indirectly accessed within the called function FC and function block FB.
Figure 6P# pointer
ANY pointer
POINTER is a parameter data type used to pass pointers. It can be considered an extension of the POINTER type, but more complex, with a length of 10 bytes. The additional 2 bytes have the following structure: the highest byte (Byte0) is fixed at B#16#10; the second byte (Byte1) indicates the data type of the region pointed to by the ANY pointer; and the next 2 bytes (BYTE3, 4) combine to form an INT, representing the length of the region specified by the ANY pointer (called the repetition factor). The remaining 6 bytes function the same as the POINTER type. The format is as follows:
Figure 7 Any pointer
Disclaimer: This article is a reprint. If it involves copyright issues, please contact us promptly for deletion (QQ: 2737591964). We apologize for any inconvenience.