Why is the constant type in the compiled code different as in my IL code?

FAQ #100129

The compiler sets automatically the correct constant type if it don't match to the instruction.


In PCDs instruction set there are two different types of constants: The 32 bit long "Constant" and the 14 bit long "K Constant" (For more accurate information read the FAQ #100123 to this topic) which are used in a different way:

  • Some instructions (e.g. the LOAD instructions LD, LDL and LDH) requires a value without a media code. In this case only a "Constant" can be inserted. A "K Constant" wan't fit here because "K" is a media type.

  • Other instructions (e.g. the CMP-instruction) requires a media code. In this case only the constant of type "K Constant" can be used. The "Constant" has no media code so it wan't fit here.

Despite this rules it is possible to use this constant types in your IL code as you want. This is only possible because the compiler replaces the wrong constant type by the right one automatically. For instance:

In IL following lines are written:


R 0

K 1
LD R 2
LD R 4
K 4


The code which will be downloaded into PCD after compilation looks like this:

000004 CMP R 0
000005 K 0
000006 CMP R 1
000007 K 1
000008 LD R 2
000009 2
000010 LD R 4
000011 4

The automatic correction of wrong constant type works also for the parameterdefinitions of a FB-Call. I.e. it is possible to define a "K Constant" as parameter of a FB call despite inside this FB the refering parameter is calling by an instruction which doesn't allow a parameter of type "K Constante":

R 0
K 1
K 2 The compiler replaces K 2 with 2, because...
... ... ...
FB 0
CMP = 1
= 2
LDL = 1
= 3 ...a LDL-instruction doesn't allow "K-Constant"

Of course the correction can not be done if the defined FB-parameter is called twice inside the FB and the allowed constant-type is different. In this case PG5 version >=1.3 will abort the compilation with an error message "FB parameter has bad context":

R 0
K 1
... ... ...
FB 0
CMP = 1 A CMP-instruction requires a media type...
= 2 ...for the second codeline
LDL = 1 A LDL-instruction does not allow a media type for the ...
= 2 ...second codeline (but "= 2" is a "K Constant") => abort

Note that in PG5 versions < 1.3 the compiler will not detect the conflict what will cause strange behaviour of your PCD!




Local FAQ Deutschland / SEdit (IL programming)

Last update: 31.05.2015 00:52

First release: 11.06.2004 14:08

Views: 6775

The requested software / document is no longer marketed by Saia-Burgess Controls AG and without technical support. It is an older software version which can be operated only on certain now no longer commercially available products.