1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
|
FUNCTION FC 1 : VOID
TITLE = Check FC 21 with L as data source
VAR_TEMP
STR : STRING;
END_VAR
BEGIN
// Check zero length (L-stack)
L P##STR
LAR1
L 254
T B [AR1, P#0.0]
L 0
T B [AR1, P#1.0]
LAR1 P#42.0
LAR2 P#42.1
AUF DB 1
CALL "LEN" (
S := #STR,
RET_VAL := MW 0,
)
__ASSERT== __STW BIE, 1
__ASSERT== __AR 1, P#42.0
__ASSERT== __AR 2, P#42.1
__ASSERT== DBNO, 1
L MW 0
__ASSERT== __ACCU 1, 0
// Check 1 length (L-stack)
L P##STR
LAR1
L 254
T B [AR1, P#0.0]
L 1
T B [AR1, P#1.0]
LAR1 P#42.0
LAR2 P#42.1
AUF DB 1
CALL "LEN" (
S := #STR,
RET_VAL := MW 0,
)
__ASSERT== __STW BIE, 1
__ASSERT== __AR 1, P#42.0
__ASSERT== __AR 2, P#42.1
__ASSERT== DBNO, 1
L MW 0
__ASSERT== __ACCU 1, 1
// Check full length (L-stack)
L P##STR
LAR1
L 254
T B [AR1, P#0.0]
L 254
T B [AR1, P#1.0]
LAR1 P#42.0
LAR2 P#42.1
AUF DB 1
CALL "LEN" (
S := #STR,
RET_VAL := MW 0,
)
__ASSERT== __STW BIE, 1
__ASSERT== __AR 1, P#42.0
__ASSERT== __AR 2, P#42.1
__ASSERT== DBNO, 1
L MW 0
__ASSERT== __ACCU 1, 254
// Check length bigger than maxlen (L-stack)
L P##STR
LAR1
L 10
T B [AR1, P#0.0]
L 100
T B [AR1, P#1.0]
LAR1 P#42.0
LAR2 P#42.1
AUF DB 1
CALL "LEN" (
S := #STR,
RET_VAL := MW 0,
)
__ASSERT== __STW BIE, 1
__ASSERT== __AR 1, P#42.0
__ASSERT== __AR 2, P#42.1
__ASSERT== DBNO, 1
L MW 0
__ASSERT== __ACCU 1, 100
END_FUNCTION
FUNCTION FC 2 : VOID
TITLE = Check FC 21 with DB as data source
BEGIN
// Check zero length (DB)
AUF DB 2
LAR1 P#DBX 0.0
L 254
T B [AR1, P#0.0]
L 0
T B [AR1, P#1.0]
LAR1 P#42.0
LAR2 P#42.1
AUF DB 1
CALL "LEN" (
S := DB2.DBSTR,
RET_VAL := MW 0,
)
__ASSERT== __STW BIE, 1
__ASSERT== __AR 1, P#42.0
__ASSERT== __AR 2, P#42.1
__ASSERT== DBNO, 1
L MW 0
__ASSERT== __ACCU 1, 0
// Check 1 length (DB)
AUF DB 2
LAR1 P#DBX 0.0
L 254
T B [AR1, P#0.0]
L 1
T B [AR1, P#1.0]
LAR1 P#42.0
LAR2 P#42.1
AUF DB 1
CALL "LEN" (
S := DB2.DBSTR,
RET_VAL := MW 0,
)
__ASSERT== __STW BIE, 1
__ASSERT== __AR 1, P#42.0
__ASSERT== __AR 2, P#42.1
__ASSERT== DBNO, 1
L MW 0
__ASSERT== __ACCU 1, 1
// Check full length (DB)
AUF DB 2
LAR1 P#DBX 0.0
L 254
T B [AR1, P#0.0]
L 254
T B [AR1, P#1.0]
LAR1 P#42.0
LAR2 P#42.1
AUF DB 1
CALL "LEN" (
S := DB2.DBSTR,
RET_VAL := MW 0,
)
__ASSERT== __STW BIE, 1
__ASSERT== __AR 1, P#42.0
__ASSERT== __AR 2, P#42.1
__ASSERT== DBNO, 1
L MW 0
__ASSERT== __ACCU 1, 254
// Check length bigger than maxlen (DB)
AUF DB 2
LAR1 P#DBX 0.0
L 10
T B [AR1, P#0.0]
L 100
T B [AR1, P#1.0]
LAR1 P#42.0
LAR2 P#42.1
AUF DB 1
CALL "LEN" (
S := DB2.DBSTR,
RET_VAL := MW 0,
)
__ASSERT== __STW BIE, 1
__ASSERT== __AR 1, P#42.0
__ASSERT== __AR 2, P#42.1
__ASSERT== DBNO, 1
L MW 0
__ASSERT== __ACCU 1, 100
END_FUNCTION
ORGANIZATION_BLOCK OB 1
BEGIN
CALL FC 1
CALL FC 2
CALL SFC 46 // Stop CPU
END_ORGANIZATION_BLOCK
DATA_BLOCK DB 1
STRUCT
TMP : INT;
END_STRUCT;
BEGIN
END_DATA_BLOCK
DATA_BLOCK DB 2
STRUCT
DBSTR : STRING;
END_STRUCT;
BEGIN
END_DATA_BLOCK
|