Controlling Your World One Contact At A Time
Pointers - Intro
Many of the instructions in the DL PLCs allow 3 ways of stating the argument or value to be used by the instruction. (Some special instructions refer to values on the arithmetic stack but we aren't referring to those.)
The first is the constant. It begins with the letter 'K'. This is from the German version of the name 'constant'. It has been used in many scientific formulas to stand for a constant - unchanging value. The value is a hex value. If used with a normal/BCD type math operation then appears as a normal value. If used with a binary (xxxB) instruction then the constant must be calculated in its hexadecimal form. (For example, decimal 12 would be Kc.) When used as an argument it cannot be changed without changing and re-downloading the program. For reference a typical instruction (LD) using the constant form of argument takes 9.0 microseconds in the DL06.
The second type is simply a memory reference. It begins with the letter 'V' and the address is in Octal. The math instruction will access that memory location and use the value found there. You must be sure that the value is compatible with the instruction. Since the CPU must make an additional memory operation this instruction takes longer than one with a constant - 11.8 microseconds.
The third type is the 'pointer' - the main focus of this page. A pointer is a V register which holds the address of a another data register. Here's where the major confusion lies in the AD PLCs. A V register is named according to the OCTAL representation of its address. But the pointer value must be in the hexadecimal version of the address.
Let's fire up Windows calculator ... I'll wait ...
Now, if you DON'T have 'Hex' 'Dec' 'Oct' 'Bin' near the top of the calculator then go to 'View' and click on 'Scientific'. Ok, now we're set.
Let's discuss the address of a V register. Let's use V2000. '2000' is the Octal representation of its address. How do we get the hexadecimal version?
Let's try the calculator first. Click the 'Oct' selector. Notice how the numbers '8' and '9' become grayed out? Sound familiar? Type in '2000' (no the 'V' is not necessary, and you couldn't enter it anyway.) Let's try the different formats.
Select 'Bin'. Ohh, a '1' and a bunch of zeroes. Not too exciting.
So let's try 'Dec'. We get '1024'.
Finally try 'Hex'. You get '400' (Remember though, for other octal numbers you may get a letter between a-f somewhere in a 'Hex' number. That's in its nature.)
This last, the '400' is what you would enter - like this
LD K400 - remember 'K' values are 'Hex' values
This saves the pointer address of V2000 into another register (in this case V2100). Ok,we don't want to haul out the Windows calculator each time we do this. But, Directsoft gives us a convenient conversion instruction called LDA. You would type in:
LDA O2000 (the thing before the '2' is the capital letter 'O' and is supplied for you as you enter the instruction. Of course it stands for Octal.)
The result of this is to place into the accumulator the decimal conversion of the octal number 2000. The result is then saved - possibly after having been manipulated by other instructions. But, to be used as a pointer it must end up in a V register.
Now that the address has been converted any math directly manipulating its value must use 'Binary' arithmetic. This is the set of math instructions with an extra 'B' on the end compared to the standard (BCD) math. This has caused many a screw up. For example, to modify a pointer so that it points to the NEXT address you would use INCB (Increment Binary) and not just INC (Increment). Also remember that nothing absolutely distinguishes that this address is holding a pointer. Be sure to use your nicknames wisely - the 'P' usage of the address get's its own nickname.
So now, how do you 'Use' a pointer. Just to be sure check the CPU manual version of the information on a given instruction. The allowable argument addresses must include 'Pointer'. Let's try an ADD instruction. (Now don't get confused. The pointer value must be modified using binary math but the pointer itself can point to any type of value. As always, it's up to you to keep things straight.)
LD V2050 - pick up the value which is in V2050
ADD P2100 - ADD (BCD) this to the value in the location WHOSE ADDRESS IS IN V2100
OUT V2051 - Send the result to V2051
If V2100 contained the value we worked out earlier in this discussion this ends up being equivalent to:
After the above three instructions there could be one like:
This will change the pointer to point to the very next location. In this sample it would now 'point to' V2001.
There have been discussions on this forum regarding the creation and accessing of storage tables using pointers. Please search for them. I also cover on of them in the next page. By the way, in keeping with the discussion of the other types of arguments, the 'pointer' method, because of yet another memory access, takes longer yet. The 'pointer' version of the LD instruction takes 33.9 microseconds, quite a jump. So use the pointer type only when needed.
Back To Introduction
Please email comments to me at the address below.