Contatto
MCP 4 – User's manual
DUEMMEGI
3.2.10- WORD(x) and pointers
The
WORD(x)
function returns the number (address) of the Word containing the parameter x, where the
parameter x is intended to be an input, an output, a virtual point, a register or a counter as in the following
examples:
A1 =
WORD
(
I18:2
)
// returns the number of the Word containing I18 channel 2
A2 =
WORD
(
I18:2.1
)
// returns the number of the Word containing I18:2.1
A3 =
WORD
(
O93
)
// returns the number of the Word containing O93 channel 1
A4 =
WORD(
V46
)
// returns the number of the Word containing V46
A5 =
WORD
(
R37
)
// returns the number of the Word containing R37
A6 =
WORD
(
C42
)
// returns the number of the Word containing C42
The following script shows how to use the
WORD(x)
function and the pointers. Suppose that the application
requires a script that, every 2 seconds, counts how many registers, in the range R0 to R10, contain a value
other tan zero; the results (the amount of register !=0) must be placed into register R15.
The function WORD(R0) returns the number of the Word where register R0 is located. The script defines a
variable (in this example its name is ptr) that at the beginning is equal to the Word number of register R0.
The notation [ptr] (inside square brackets) returns the content of the “pointed” register. In the following script,
the R15 value will be increased by 1 every time the content of each register addressed in the loop is other
than zero. At each iteration, the value of the pointer will be increased by 1 in order to point to the next Word
and therefore to the next register. The notation ptr += 1 is equivalent to ptr = ptr + 1, as R15 = R15 + 1 can be
written as R15 +=1.
When the pointer become greater than the address of R10, the loop will be interrupted and the script ends.
script
1
trigger
= 2
var
ptr
ptr =
WORD
(
R0
)
R15
= 0
LOOP:
if
ptr <=
WORD
(
R10
)
then
if
[ptr] <> 0
then
R15
=
R15
+ 1
endif
ptr += 1
goto
LOOP
endif
endscript
Another example: the day of the month is located in the Word 1924 (see RAM map); to copy this value (and
therefore the containing of the Word 1924) to register R2, the following instruction can be written:
ptr = 1924
R2
= [ptr]
On the contrary, it is possible to copy the containing of R2 in the Word 1924 as follows:
ptr = 1924
[ptr] =
R2
The pointer are useful when the Word to be accessed to (both for reading and writing) cannot be identified in
other ways (in other words when it cannot be identified by notations as Cx, Ry, etc.).
Page 42 of 87
Rel.: 1.2 October 2018
DUEMMEGI
s.r.l. - Via Longhena, 4 – 20139 MILANO
Tel. 02/57300377 - Fax 02/55213686 –
www.duemmegi.it