struct.awl 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. DATA_BLOCK DB 99
  2. STRUCT
  3. VAR0 : INT := 111;
  4. VAR10 : STRUCT
  5. VAR10_1 : INT := 101;
  6. VAR10_2 : ARRAY [1 .. 2 ] OF INT := 1, 2;
  7. VAR10_3 : ARRAY [1 .. 2 ] OF STRUCT
  8. VAR10_3_1 : INT := 1031;
  9. VAR10_3_2 : ARRAY [1 .. 2 ] OF INT := 1, 2;
  10. END_STRUCT;
  11. VAR10_4 : INT;
  12. END_STRUCT;
  13. VAR20 : ARRAY [4 .. 5] OF STRUCT
  14. VAR20_1 : WORD;
  15. END_STRUCT
  16. VAR1 : DWORD;
  17. END_STRUCT;
  18. BEGIN
  19. VAR0 := 10101;
  20. VAR10.VAR10_1 := 101;
  21. VAR10.VAR10_2[1] := 1;
  22. VAR10.VAR10_2[2] := 2;
  23. // VAR10.VAR10_3[1].VAR10_3_1 := 1031;
  24. // VAR10.VAR10_3[1].VAR10_3_2[1] := 1;
  25. // VAR10.VAR10_3[1].VAR10_3_2[2] := 2;
  26. VAR10.VAR10_3[2].VAR10_3_1 := 1032;
  27. VAR10.VAR10_3[2].VAR10_3_2[1] := 3;
  28. VAR10.VAR10_3[2].VAR10_3_2[2] := 4;
  29. VAR10.VAR10_4 := 104;
  30. VAR20[4].VAR20_1 := W#16#204;
  31. VAR20[5].VAR20_1 := W#16#205;
  32. VAR1 := DW#16#111;
  33. END_DATA_BLOCK
  34. FUNCTION_BLOCK FB 1
  35. VAR_INPUT
  36. FBVAR0 : DINT;
  37. FBVAR1 : STRUCT
  38. FBVAR1_1 : INT;
  39. FBVAR1_2 : DINT;
  40. FBVAR1_3 : STRUCT
  41. FBVAR1_3_1 : INT;
  42. FBVAR1_3_2 : INT;
  43. END_STRUCT;
  44. END_STRUCT;
  45. FBVAR2 : ARRAY [1 .. 2] OF STRUCT
  46. FBVAR2_1 : DWORD;
  47. FBVAR2_2 : ARRAY [1 .. 2] OF WORD;
  48. END_STRUCT;
  49. END_VAR
  50. VAR_TEMP
  51. FBTMP0 : STRUCT
  52. FBTMP0_1 : INT;
  53. FBTMP0_2 : DINT;
  54. END_STRUCT;
  55. END_VAR
  56. BEGIN
  57. // Check input variables
  58. L #FBVAR0
  59. __ASSERT== __ACCU 1, L#9100
  60. L #FBVAR1.FBVAR1_1
  61. __ASSERT== __ACCU 1, 9101
  62. L #FBVAR1.FBVAR1_2
  63. __ASSERT== __ACCU 1, L#9102
  64. L #FBVAR1.FBVAR1_3.FBVAR1_3_1
  65. __ASSERT== __ACCU 1, 9103
  66. L #FBVAR1.FBVAR1_3.FBVAR1_3_2
  67. __ASSERT== __ACCU 1, 9104
  68. L #FBVAR2[1].FBVAR2_1
  69. __ASSERT== __ACCU 1, DW#16#9105
  70. L #FBVAR2[1].FBVAR2_2[1]
  71. __ASSERT== __ACCU 1, W#16#9106
  72. L #FBVAR2[1].FBVAR2_2[2]
  73. __ASSERT== __ACCU 1, W#16#9107
  74. L #FBVAR2[2].FBVAR2_1
  75. __ASSERT== __ACCU 1, DW#16#9108
  76. L #FBVAR2[2].FBVAR2_2[1]
  77. __ASSERT== __ACCU 1, W#16#9109
  78. L #FBVAR2[2].FBVAR2_2[2]
  79. __ASSERT== __ACCU 1, W#16#9110
  80. // Check TEMP variables
  81. L 11
  82. T #FBTMP0.FBTMP0_1
  83. L L#111
  84. T #FBTMP0.FBTMP0_2
  85. L #FBTMP0.FBTMP0_1
  86. __ASSERT== __ACCU 1, 11
  87. L #FBTMP0.FBTMP0_2
  88. __ASSERT== __ACCU 1, 111
  89. END_FUNCTION_BLOCK
  90. DATA_BLOCK DB 1
  91. FB 1
  92. BEGIN
  93. FBVAR0 := L#100;
  94. FBVAR1.FBVAR1_1 := 101;
  95. FBVAR1.FBVAR1_2 := L#102;
  96. FBVAR1.FBVAR1_3.FBVAR1_3_1 := 103;
  97. FBVAR1.FBVAR1_3.FBVAR1_3_2 := 104;
  98. FBVAR2[1].FBVAR2_1 := DW#16#105;
  99. FBVAR2[1].FBVAR2_2[1] := W#16#106;
  100. FBVAR2[1].FBVAR2_2[2] := W#16#107;
  101. FBVAR2[2].FBVAR2_1 := DW#16#108;
  102. FBVAR2[2].FBVAR2_2[1] := W#16#109;
  103. FBVAR2[2].FBVAR2_2[2] := W#16#110;
  104. END_DATA_BLOCK
  105. FUNCTION FC 1 : VOID
  106. VAR_INPUT
  107. FCVAR0 : DINT;
  108. FCVAR1 : STRUCT
  109. FCVAR1_1 : INT;
  110. FCVAR1_2 : DINT;
  111. FCVAR1_3 : STRUCT
  112. FCVAR1_3_1 : INT;
  113. FCVAR1_3_2 : INT;
  114. END_STRUCT;
  115. END_STRUCT;
  116. FCVAR2 : ARRAY [1 .. 2] OF STRUCT
  117. FCVAR2_1 : DWORD;
  118. FCVAR2_2 : ARRAY [1 .. 2] OF WORD;
  119. END_STRUCT;
  120. END_VAR
  121. VAR_TEMP
  122. FCTMP0 : STRUCT
  123. FCTMP0_1 : INT;
  124. FCTMP0_2 : DINT;
  125. END_STRUCT;
  126. END_VAR
  127. BEGIN
  128. // Check input variables
  129. L #FCVAR0
  130. __ASSERT== __ACCU 1, L#9100
  131. L #FCVAR1.FCVAR1_1
  132. __ASSERT== __ACCU 1, 9101
  133. L #FCVAR1.FCVAR1_2
  134. __ASSERT== __ACCU 1, L#9102
  135. L #FCVAR1.FCVAR1_3.FCVAR1_3_1
  136. __ASSERT== __ACCU 1, 9103
  137. L #FCVAR1.FCVAR1_3.FCVAR1_3_2
  138. __ASSERT== __ACCU 1, 9104
  139. L #FCVAR2[1].FCVAR2_1
  140. __ASSERT== __ACCU 1, DW#16#9105
  141. L #FCVAR2[1].FCVAR2_2[1]
  142. __ASSERT== __ACCU 1, W#16#9106
  143. L #FCVAR2[1].FCVAR2_2[2]
  144. __ASSERT== __ACCU 1, W#16#9107
  145. L #FCVAR2[2].FCVAR2_1
  146. __ASSERT== __ACCU 1, DW#16#9108
  147. L #FCVAR2[2].FCVAR2_2[1]
  148. __ASSERT== __ACCU 1, W#16#9109
  149. L #FCVAR2[2].FCVAR2_2[2]
  150. __ASSERT== __ACCU 1, W#16#9110
  151. // Check TEMP variables
  152. L 11
  153. T #FCTMP0.FCTMP0_1
  154. L L#111
  155. T #FCTMP0.FCTMP0_2
  156. L #FCTMP0.FCTMP0_1
  157. __ASSERT== __ACCU 1, 11
  158. L #FCTMP0.FCTMP0_2
  159. __ASSERT== __ACCU 1, 111
  160. END_FUNCTION
  161. // Data block for FC 1 / FB 1 parameter passing.
  162. DATA_BLOCK DB 10
  163. STRUCT
  164. DBVAR0 : DINT;
  165. DBVAR1 : STRUCT
  166. DBVAR1_1 : INT;
  167. DBVAR1_2 : DINT;
  168. DBVAR1_3 : STRUCT
  169. DBVAR1_3_1 : INT;
  170. DBVAR1_3_2 : INT;
  171. END_STRUCT;
  172. END_STRUCT;
  173. DBVAR2 : ARRAY [1 .. 2] OF STRUCT
  174. DBVAR2_1 : DWORD;
  175. DBVAR2_2 : ARRAY [1 .. 2] OF WORD;
  176. END_STRUCT;
  177. END_STRUCT;
  178. BEGIN
  179. DBVAR0 := L#9100;
  180. DBVAR1.DBVAR1_1 := 9101;
  181. DBVAR1.DBVAR1_2 := L#9102;
  182. DBVAR1.DBVAR1_3.DBVAR1_3_1 := 9103;
  183. DBVAR1.DBVAR1_3.DBVAR1_3_2 := 9104;
  184. DBVAR2[1].DBVAR2_1 := DW#16#9105;
  185. DBVAR2[1].DBVAR2_2[1] := W#16#9106;
  186. DBVAR2[1].DBVAR2_2[2] := W#16#9107;
  187. DBVAR2[2].DBVAR2_1 := DW#16#9108;
  188. DBVAR2[2].DBVAR2_2[1] := W#16#9109;
  189. DBVAR2[2].DBVAR2_2[2] := W#16#9110;
  190. END_DATA_BLOCK
  191. ORGANIZATION_BLOCK OB 1
  192. BEGIN
  193. // Check the DB 99 initial values.
  194. AUF DB 99
  195. L DBLG
  196. __ASSERT== __ACCU 1, 30
  197. L DBW 0 // DB99.VAR0
  198. __ASSERT== __ACCU 1, 10101
  199. L DBW 2 // DB99.VAR10.VAR10_1
  200. __ASSERT== __ACCU 1, 101
  201. L DBW 4 // DB99.VAR10.VAR10_2[1]
  202. __ASSERT== __ACCU 1, 1
  203. L DBW 6 // DB99.VAR10.VAR10_2[2]
  204. __ASSERT== __ACCU 1, 2
  205. L DBW 8 // DB99.VAR10.VAR10_3[1].VAR10_3_1
  206. __ASSERT== __ACCU 1, 1031
  207. L DBW 10 // DB99.VAR10.VAR10_3[1].VAR10_3_2[1]
  208. __ASSERT== __ACCU 1, 1
  209. L DBW 12 // DB99.VAR10.VAR10_3[1].VAR10_3_2[2]
  210. __ASSERT== __ACCU 1, 2
  211. L DBW 14 // DB99.VAR10.VAR10_3[2].VAR10_3_1
  212. __ASSERT== __ACCU 1, 1032
  213. L DBW 16 // DB99.VAR10.VAR10_3[2].VAR10_3_2[1]
  214. __ASSERT== __ACCU 1, 3
  215. L DBW 18 // DB99.VAR10.VAR10_3[2].VAR10_3_2[2]
  216. __ASSERT== __ACCU 1, 4
  217. L DBW 20 // DB99.VAR10.VAR10_4
  218. __ASSERT== __ACCU 1, 104
  219. L DBW 22 // DB99.VAR20[4].VAR20_1
  220. __ASSERT== __ACCU 1, W#16#204
  221. L DBW 24 // DB99.VAR20[5].VAR20_1
  222. __ASSERT== __ACCU 1, W#16#205
  223. L DBD 26 // DB99.VAR1
  224. __ASSERT== __ACCU 1, DW#16#111
  225. // Check symbolic DB 99 access.
  226. L DB99.VAR0
  227. __ASSERT== __ACCU 1, 10101
  228. L DB99.VAR10.VAR10_1
  229. __ASSERT== __ACCU 1, 101
  230. L DB99.VAR10.VAR10_2[1]
  231. __ASSERT== __ACCU 1, 1
  232. L DB99.VAR10.VAR10_2[2]
  233. __ASSERT== __ACCU 1, 2
  234. L DB99.VAR10.VAR10_3[1].VAR10_3_1
  235. __ASSERT== __ACCU 1, 1031
  236. L DB99.VAR10.VAR10_3[1].VAR10_3_2[1]
  237. __ASSERT== __ACCU 1, 1
  238. L DB99.VAR10.VAR10_3[1].VAR10_3_2[2]
  239. __ASSERT== __ACCU 1, 2
  240. L DB99.VAR10.VAR10_3[2].VAR10_3_1
  241. __ASSERT== __ACCU 1, 1032
  242. L DB99.VAR10.VAR10_3[2].VAR10_3_2[1]
  243. __ASSERT== __ACCU 1, 3
  244. L DB99.VAR10.VAR10_3[2].VAR10_3_2[2]
  245. __ASSERT== __ACCU 1, 4
  246. L DB99.VAR10.VAR10_4
  247. __ASSERT== __ACCU 1, 104
  248. L DB99.VAR20[4].VAR20_1
  249. __ASSERT== __ACCU 1, W#16#204
  250. L DB99.VAR20[5].VAR20_1
  251. __ASSERT== __ACCU 1, W#16#205
  252. L DB99.VAR1
  253. __ASSERT== __ACCU 1, DW#16#111
  254. // Check DB 10 initial values
  255. AUF DB 10
  256. L DBLG
  257. __ASSERT== __ACCU 1, 30
  258. L DB10.DBVAR0
  259. __ASSERT== __ACCU 1, L#9100
  260. L DB10.DBVAR1.DBVAR1_1
  261. __ASSERT== __ACCU 1, 9101
  262. L DB10.DBVAR1.DBVAR1_2
  263. __ASSERT== __ACCU 1, L#9102
  264. L DB10.DBVAR1.DBVAR1_3.DBVAR1_3_1
  265. __ASSERT== __ACCU 1, 9103
  266. L DB10.DBVAR1.DBVAR1_3.DBVAR1_3_2
  267. __ASSERT== __ACCU 1, 9104
  268. L DB10.DBVAR2[1].DBVAR2_1
  269. __ASSERT== __ACCU 1, DW#16#9105
  270. L DB10.DBVAR2[1].DBVAR2_2[1]
  271. __ASSERT== __ACCU 1, W#16#9106
  272. L DB10.DBVAR2[1].DBVAR2_2[2]
  273. __ASSERT== __ACCU 1, W#16#9107
  274. L DB10.DBVAR2[2].DBVAR2_1
  275. __ASSERT== __ACCU 1, DW#16#9108
  276. L DB10.DBVAR2[2].DBVAR2_2[1]
  277. __ASSERT== __ACCU 1, W#16#9109
  278. L DB10.DBVAR2[2].DBVAR2_2[2]
  279. __ASSERT== __ACCU 1, W#16#9110
  280. // Check DB 1 (FB 1 instance DB) initial values
  281. AUF DB 1
  282. L DBLG
  283. __ASSERT== __ACCU 1, 30
  284. L DB1.FBVAR0
  285. __ASSERT== __ACCU 1, L#100
  286. L DB1.FBVAR1.FBVAR1_1
  287. __ASSERT== __ACCU 1, 101
  288. L DB1.FBVAR1.FBVAR1_2
  289. __ASSERT== __ACCU 1, L#102
  290. L DB1.FBVAR1.FBVAR1_3.FBVAR1_3_1
  291. __ASSERT== __ACCU 1, 103
  292. L DB1.FBVAR1.FBVAR1_3.FBVAR1_3_2
  293. __ASSERT== __ACCU 1, 104
  294. L DB1.FBVAR2[1].FBVAR2_1
  295. __ASSERT== __ACCU 1, DW#16#105
  296. L DB1.FBVAR2[1].FBVAR2_2[1]
  297. __ASSERT== __ACCU 1, W#16#106
  298. L DB1.FBVAR2[1].FBVAR2_2[2]
  299. __ASSERT== __ACCU 1, W#16#107
  300. L DB1.FBVAR2[2].FBVAR2_1
  301. __ASSERT== __ACCU 1, DW#16#108
  302. L DB1.FBVAR2[2].FBVAR2_2[1]
  303. __ASSERT== __ACCU 1, W#16#109
  304. L DB1.FBVAR2[2].FBVAR2_2[2]
  305. __ASSERT== __ACCU 1, W#16#110
  306. // Call FB with STRUCT and ARRAY parameters.
  307. CALL FB 1, DB 1 (
  308. FBVAR0 := DB10.DBVAR0,
  309. FBVAR1 := DB10.DBVAR1,
  310. FBVAR2 := DB10.DBVAR2,
  311. )
  312. // Call FC with STRUCT and ARRAY parameters.
  313. CALL FC 1 (
  314. FCVAR0 := DB10.DBVAR0,
  315. FCVAR1 := DB10.DBVAR1,
  316. FCVAR2 := DB10.DBVAR2,
  317. )
  318. CALL SFC 46 // STOP CPU
  319. END_ORGANIZATION_BLOCK