Why is the constant type in the compiled code different as in my IL code?
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:
The code which will be downloaded into PCD after compilation looks like this:
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":
|K 2||The compiler replaces K 2 with 2, because...|
|= 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":
|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 02:52
First release: 11.06.2004 16:08