The
PLC
Guy

  Controlling Your World One Contact At A Time  


Pointers - Recipes


In the previous page we presented the idea of 'pointers' Now for a practical example.

We use recipes, groups of values used when performing a particular operation, perhaps running a particular type of product. The recipes for all the machine's products are stored in a block of memory. The particular recipe will be referred to as recipe R. The particular item whithin the recipe will be referred to as item I. Let's say you want to access recipe R (stored in V2000) item I (stored in V2001). The recipe size is 16 words (hex 10). The table of stored recipes begins at V10000 (it's a nice big block, remember to make it retentive).

LD V2000 - (R) recipe numbers from 0 to ?? (This value is in 'binary' not 'BCD')
MULB K10 - this creates and offset to the start of the recipe - remember, this is the hex version of the block size.
LD V2001 - (I) the item within the recipe
ADDBS - this adds together the off set to the start of the recipe to the offset to the item
LDA 010000 - this gets the start of the table in binary form
ADDBS - now we have a 'pointer' in the accumulator to the item in the table
OUT V2002 - this will hold this pointer

Now we can use the pointer simply by
LD P2002 - which gets the item within the recipe area.

or

OUT P2002 - which stores something to the specific item location.



But we typically move the whole recipe from the storage area to a common area. Any changes to the recipe are made in that common area. The recipe can later be stored. Let's look at this.

We are going to have a central storage for our recipe at V3000. This is the current working recipe so the main program doesn't have to keep calculating a pointer all the time.

We use part of the above instructions to generate a pointer. Since we are getting a whole recipe we won't need the 'item' portion

LD V2000 - recipe numbers from 0 to ?? (This value is in 'binary' not 'BCD')
MULB K10 - this creates and offset to the start of the recipe
LDA 010000 - this gets the start of the table in binary form
ADDBS - now we have a 'pointer' in the accumulator to the start of the recipe in the table
OUT V2002 - this will hold this pointer

LDA O3000 - get a pointer to the central storage point
OUT V2003 - this makes for a convenient storage even though it's constant.

'Get' a recipe and store in the central storage (V3000)

LD K10 - this is our recipe size in hex
LD V2002 - this point to the specific recipe area in the table
MOV P2003 - this moves the 16 words from the table to the central storage.


'Store' a recipe, possibly after modification, into its place in the table

LD K10 - this is our recipe size in hex
LD V2003 - this points to the central storage area
MOV P2002 - this moves the 16 words from the central storage to its place in the table.

(Yes I know the 'LD V2003' could have been 'LDA O3000', but I like the symmetry of the two moves especially when they're in adjacent subroutines.)

Back To Introduction

Please email comments to me at the address below.





Copyright © 2011 Bernard Carlton
berniec@theplcguy.com