Indirect addressing DM in CX-Programmer
Indirect Addressing in CX-Programmer: *D vs. @D
In CX-Programmer, indirect addressing allows accessing data dynamically using an address stored in another memory location. The *D and @D operators determine how the address is interpreted.
1. Key Difference Between *D and @D
| Operator | Address Format | Explanation |
|---|---|---|
*D |
BCD (Binary-Coded Decimal) | The value in the pointer register is treated as a BCD number, meaning it can only store values 0-9999. |
@D |
Binary | The value in the pointer register is treated as a binary number, allowing full 16-bit addressing (0-65535). |
2. Using *D (BCD Indirect Addressing)
*D treats the pointer value as BCD, meaning only valid BCD values (0–9999) can be used. If a non-BCD value is in the pointer, it may cause errors.
Example: Indirect MOV Using *D
If:
-
D0contains#0200(BCD format, meaning 200 decimal). -
D200holds#1234.
Then:
MOV *D0 D10What Happens?
-
D0contains#200(BCD). -
*D0means accessD200. - The value in
D200(#1234) is moved toD10.
✅ Correct Usage: D0 contains a valid BCD address (e.g., #0200).
❌ Incorrect Usage Example: If D0 contains 021A, this is not a valid BCD value because A is not a decimal digit. This would cause an error or unexpected behavior.
3. Using @D (Binary Indirect Addressing)
@D treats the pointer as a binary value, allowing a full range of addresses (0–65535). This is generally more flexible and avoids BCD limitations.
Example: Indirect MOV Using @D
If:
-
D0contains&200(binary). -
D200holds&5678.
Then:
MOV @D0 D20What Happens?
-
D0contains&200(binary). -
@D0means accessD200. - The value in
D200(&5678) is moved toD20.
✅ Advantage: @D allows full 16-bit addressing, unlike *D which is limited to BCD.
✅ More Common Use Case: Most PLC programmers prefer @D for flexibility.
4. When to Use *D vs. @D
| Operator | Use Case |
|---|---|
*D (BCD Indirect) |
When working with BCD-encoded data (legacy systems, HMI settings, etc.). |
@D (Binary Indirect) |
When working with normal binary memory addressing (recommended in most cases). |
5. Summary
-
*Dis for BCD-formatted addresses (0-9999), which may cause errors if non-BCD values are used. -
@Dis for binary-formatted addresses (0-65535) and is generally more versatile.
Recommendation
Unless working with BCD-encoded data, @D is preferred because it avoids BCD conversion issues.