C
<p>Hello,
<p>I am trying to write a function that will take in a DB number, starting address, address offset, number of words, comparison value, and return a count of non true equal comparisons. I have it working with the exception of being able to pass in the starting address. Below is what I have so far (From and .AWL source file). Specifically, I would like to get away from "hard coding" in the line "L P#DBX 30.0" so that this address is passed into the function.
<p>Thanks,
<p>Chris
<pre>
FUNCTION "Data_Counter" : VOID
TITLE =Count_Val
//Routine will take in a DB number, a comparison value, number of
comparisons to
//make, and an offset value (number of bytes between data words to compare)
VERSION : 0.1
VAR_INPUT
Comparison_Val : INT ; //The value comparing data against
DBNUM : BLOCK_DB ; //Data Block number
Offset : INT ; //How many bytes between words to compare
Quantity_Data : INT ; //How many words to compare
END_VAR
VAR_OUTPUT
Count_Val : INT ; //Number of true comparisons in the Range
END_VAR
VAR_TEMP
Cycle : INT ; //Cycle number for the counting routine
Count : INT ; //Current count of the true comparisons
END_VAR
BEGIN
NETWORK
TITLE =Count routine
//Count the words that do not equal the comparison value
OPN #DBNUM; //Open the data block
L P#DBX 30.0; //Starting Address, How do I do this with a
variable?
LAR1 ; //Put the starting address in address reg 1
L #Quantity_Data; //Load the number of Items to compare
Next: T #Cycle;
L W [AR1,P#0.0]; //Load the data word pointed at by AR1, offset by
zero
L #Comparison_Val;
==I ;
JC yes; //if =0, jump around incrementing the counter
L #Count;
INC 1;
T #Count;
L #Offset;
+AR1 ; //add Offset to the address register 1 to get to next word
JU jump;
yes: L #Offset; //add Offset to address register 1 to get to the next
word
+AR1 ;
jump: L #Cycle;
LOOP Next;
L #Count;
T #Count_Val; //transfer out the count value
END_FUNCTION
</pre>
<p>I am trying to write a function that will take in a DB number, starting address, address offset, number of words, comparison value, and return a count of non true equal comparisons. I have it working with the exception of being able to pass in the starting address. Below is what I have so far (From and .AWL source file). Specifically, I would like to get away from "hard coding" in the line "L P#DBX 30.0" so that this address is passed into the function.
<p>Thanks,
<p>Chris
<pre>
FUNCTION "Data_Counter" : VOID
TITLE =Count_Val
//Routine will take in a DB number, a comparison value, number of
comparisons to
//make, and an offset value (number of bytes between data words to compare)
VERSION : 0.1
VAR_INPUT
Comparison_Val : INT ; //The value comparing data against
DBNUM : BLOCK_DB ; //Data Block number
Offset : INT ; //How many bytes between words to compare
Quantity_Data : INT ; //How many words to compare
END_VAR
VAR_OUTPUT
Count_Val : INT ; //Number of true comparisons in the Range
END_VAR
VAR_TEMP
Cycle : INT ; //Cycle number for the counting routine
Count : INT ; //Current count of the true comparisons
END_VAR
BEGIN
NETWORK
TITLE =Count routine
//Count the words that do not equal the comparison value
OPN #DBNUM; //Open the data block
L P#DBX 30.0; //Starting Address, How do I do this with a
variable?
LAR1 ; //Put the starting address in address reg 1
L #Quantity_Data; //Load the number of Items to compare
Next: T #Cycle;
L W [AR1,P#0.0]; //Load the data word pointed at by AR1, offset by
zero
L #Comparison_Val;
==I ;
JC yes; //if =0, jump around incrementing the counter
L #Count;
INC 1;
T #Count;
L #Offset;
+AR1 ; //add Offset to the address register 1 to get to next word
JU jump;
yes: L #Offset; //add Offset to address register 1 to get to the next
word
+AR1 ;
jump: L #Cycle;
LOOP Next;
L #Count;
T #Count_Val; //transfer out the count value
END_FUNCTION
</pre>