What is the difference between the media types "Constant" and "K Constant"?
FAQ #100123
The main difference is the different range of values for this two types "Constant" (type "Const" in the Symbol Editor) and "K Constant" (type "K" in the Symbol Editor).
Symbol | min value | max value |
Const | -2'147'483'648 | 2'147'483'647 |
K | 0 | 16383 |
The difference can be explained with the structure of a codeline, which has the length of 32 bit:
ADD | K | 100 | ; 1. Codeline of instruction |
R | 100 | ; 2. Codeline of instruction | |
R | 101 | ; 3. Codeline of instruction |
All informations of each codeline are stored into 32 Bit (4 byte). Since the first codeline needs 18 bits for instruction (e.g. ADD) and media code (K, R, I,...), there are 14 bits left which can - in case the media code is K - be used for the value of the "K constant". Therefore the value range of the "K constant" is 0..16383.
A "K constant" is marked by the media code (bits 14 and 15 are high) and so it can be used instead of e.g. a register (given the instruction supports it).
Note that the "K Constant" can only be used as parameter for instruction that requires a media code.
Load instructions (LD, LDL, LDH) only accept "Constants" without mediacode for its second codeline. See below:
LD | R | 200 | ; Load register 200 |
2147483647 | ; with the value 2147483647 |
Since on the second codeline of the LD instruction no media type is allowed but only a value is possible, the whole 32 bit of the codeline may be used as the value (-2'147'483'648..2'147'483'647) of this constant.
Note that the "Constant" only can be used with Load Mnemonics; further on it never can not be passed to an FB as parameter.
Categories
Local FAQ Deutschland / Fupla
Local FAQ Deutschland / SEdit (IL programming)
Local FAQ Deutschland / Symbol Editor
PG5 2.0 / Fupla
PG5 2.0 / SEdit (IL programming)
PG5 2.0 / Symbol Editor
Last update: 15.07.2016 13:32
First release: 11.06.2004 10:37
Views: 12997