dbpointer.awl 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. ORGANIZATION_BLOCK OB 1
  2. VAR_TEMP
  3. TMPDUMMY : INT;
  4. DTTEMP : DATE_AND_TIME;
  5. END_VAR
  6. BEGIN
  7. // Check forwarding of compound data type to FC
  8. // (This will create implicit DB pointers)
  9. AUF DB 42
  10. LAR1 P##DTTEMP
  11. L DW#16#12345678
  12. T D [AR1, P#0.0]
  13. L DW#16#87654321
  14. T DBD 4
  15. L DW#16#AABBCCDD
  16. T D [AR1, P#4.0]
  17. L DW#16#DDCCBBAA
  18. T DBD 8
  19. CALL FC 1 (
  20. DTTEMP := #DTTEMP,
  21. DTDB := DB42.DTVAR1,
  22. )
  23. // Check forwarding of compound data type from FB to FC
  24. CALL FB 10, DB 10 (
  25. DUMMYIN := 42,
  26. DTVAR := DB42.DTVAR1,
  27. )
  28. // Check FB compound data type IN_OUT parameter semantics.
  29. L 42
  30. T MW 0
  31. L 43
  32. T MW 2
  33. L 44
  34. T MW 4
  35. AUF DB 42
  36. L DW#16#11223344 // DB42.DTVAR4
  37. T DBD 30
  38. L DW#16#55667788 // DB42.DTVAR4
  39. T DBD 34
  40. CALL FB 20, DB 20 (
  41. DTIN := DB42.DTVAR2,
  42. INTIN := MW 0,
  43. DTOUT := DB42.DTVAR3,
  44. INTOUT := MW 2,
  45. DTINOUT := DB42.DTVAR4,
  46. INTINOUT := MW 4,
  47. )
  48. // Check modified DTINOUT (DB42.DTVAR4)
  49. AUF DB 42
  50. L DBD 30
  51. __ASSERT== __ACCU 1, DW#16#12131415
  52. L DBD 34
  53. __ASSERT== __ACCU 1, DW#16#16171819
  54. // Check explicit DB-pointer parameters
  55. CALL FC 50 (
  56. FCPTR1 := P#DB50.DBX 10.0,
  57. FCPTR2 := DB50.DBX 10.1,
  58. FCPTR3 := P#M 99.7,
  59. FCPTR4 := M 99.7,
  60. FCPTR5 := P#7.1,
  61. FCPTR6 := DB1.DBVAR2[2].V2,
  62. FCPTR7 := #TMPDUMMY,
  63. FCOUTPTR1 := M 98.7,
  64. RET_VAL := A 97.6,
  65. )
  66. CALL FB 50, DB 50 (
  67. FBPTR1 := P#DB50.DBX 10.0,
  68. FBPTR2 := DB50.DBX 10.1,
  69. FBPTR3 := P#M 99.7,
  70. FBPTR4 := M 99.7,
  71. FBPTR5 := P#7.1,
  72. FBPTR6 := DB1.DBVAR2[2].V2,
  73. FBPTR7 := #TMPDUMMY,
  74. )
  75. // Pass DATE_AND_TIME immediate passing to FC and FB parameters.
  76. // This is an awlsim extension.
  77. CALL FC 60 (
  78. FC_DTIMM_0 := DT#1998-02-03-16:17:20.211,
  79. )
  80. CALL FB 60, DB 60 (
  81. FB_DTIMM_0 := DT#1998-02-03-16:17:20.211,
  82. )
  83. // Check fully qualified DB variable pointer.
  84. // This is an awlsim extension.
  85. L P#DB42.DTVAR1
  86. __ASSERT== __ACCU 1, P#DBX 4.0
  87. L P#"Data".DTVAR1
  88. __ASSERT== __ACCU 1, P#DBX 4.0
  89. L P#DB42.ARR1[1].V1
  90. __ASSERT== __ACCU 1, P#DBX 38.0
  91. L P#DB42.ARR1[2].V2
  92. __ASSERT== __ACCU 1, P#DBX 44.0
  93. CALL FC 70 (
  94. FCP1 := P#DB42.ARR1[1].V1,
  95. )
  96. CALL "FC70_sym" (
  97. FCP1 := P#DB42.ARR1[1].V1,
  98. )
  99. CALL FB 70, DB 70 (
  100. FBP1 := P#DB42.ARR1[1].V1,
  101. )
  102. CALL SFC 46 // STOP CPU
  103. END_ORGANIZATION_BLOCK
  104. DATA_BLOCK DB 1
  105. STRUCT
  106. DBVAR1 : INT;
  107. DBVAR2 : ARRAY[1 .. 6] of STRUCT
  108. V1 : INT;
  109. V2 : INT;
  110. END_STRUCT;
  111. DBVAR3 : INT;
  112. END_STRUCT
  113. BEGIN
  114. END_DATA_BLOCK
  115. FUNCTION_BLOCK FB 20
  116. VAR_INPUT
  117. DTIN : DATE_AND_TIME;
  118. INTIN : INT;
  119. END_VAR
  120. VAR_OUTPUT
  121. DTOUT : DATE_AND_TIME;
  122. INTOUT : INT;
  123. END_VAR
  124. VAR_IN_OUT
  125. DTINOUT : DATE_AND_TIME;
  126. INTINOUT : INT;
  127. END_VAR
  128. VAR
  129. DTSTAT : DATE_AND_TIME;
  130. INTSTAT : INT;
  131. END_VAR
  132. VAR_TEMP
  133. DBNR : INT;
  134. END_VAR
  135. BEGIN
  136. // Check all variable addresses
  137. L P##DTIN
  138. __ASSERT== __ACCU 1, P#DIX 0.0
  139. L P##INTIN
  140. __ASSERT== __ACCU 1, P#DIX 8.0
  141. L P##DTOUT
  142. __ASSERT== __ACCU 1, P#DIX 10.0
  143. L P##INTOUT
  144. __ASSERT== __ACCU 1, P#DIX 18.0
  145. L P##DTINOUT // 6 byte DB-ptr
  146. __ASSERT== __ACCU 1, P#DIX 20.0
  147. L P##INTINOUT
  148. __ASSERT== __ACCU 1, P#DIX 26.0
  149. L P##DTSTAT
  150. __ASSERT== __ACCU 1, P#DIX 28.0
  151. L P##INTSTAT
  152. __ASSERT== __ACCU 1, P#DIX 36.0
  153. // Check DTINOUT data (via DB ptr)
  154. L P##DTINOUT
  155. LAR1
  156. L W [AR1, P#0.0] // Get DB-nr from DB-ptr
  157. T #DBNR
  158. __ASSERT== __ACCU 1, 42
  159. AUF DB [#DBNR]
  160. L D [AR1, P#2.0] // Get address from DB-ptr
  161. LAR1
  162. __ASSERT== __ACCU 1, P#DBX 30.0
  163. L D [AR1, P#0.0] // Get DTINOUT data
  164. __ASSERT== __ACCU 1, DW#16#11223344
  165. L D [AR1, P#4.0] // Get DTINOUT data
  166. __ASSERT== __ACCU 1, DW#16#55667788
  167. // Modify DTINOUT data (via DB ptr)
  168. L DW#16#12131415
  169. T D [AR1, P#0.0] // Write DTINOUT data
  170. L DW#16#16171819
  171. T D [AR1, P#4.0] // Write DTINOUT data
  172. END_FUNCTION_BLOCK
  173. DATA_BLOCK DB 20
  174. FB 20
  175. BEGIN
  176. END_DATA_BLOCK
  177. FUNCTION FC 1 : VOID
  178. VAR_INPUT
  179. DTTEMP : DATE_AND_TIME;
  180. DTDB : DATE_AND_TIME;
  181. END_VAR
  182. VAR_TEMP
  183. DBNR : INT;
  184. END_VAR
  185. BEGIN
  186. // Load #DTTEMP into AR1
  187. L P##DTTEMP
  188. LAR1
  189. UD DW#16#FF000000
  190. __ASSERT== __ACCU 1, DW#16#87000000
  191. // Check the DB-pointer pointed to by #DTTEMP
  192. L W [AR1, P#0.0]
  193. __ASSERT== __ACCU 1, 0 // DB-nr
  194. T #DBNR
  195. L D [AR1, P#2.0]
  196. __ASSERT== __ACCU 1, DW#16#87000010
  197. LAR2
  198. AUF DB [#DBNR]
  199. // Check the actual values
  200. L D [AR2, P#0.0]
  201. __ASSERT== __ACCU 1, DW#16#12345678
  202. L D [AR2, P#4.0]
  203. __ASSERT== __ACCU 1, DW#16#AABBCCDD
  204. // Load #DTDB into AR1
  205. L P##DTDB
  206. LAR1
  207. UD DW#16#FF000000
  208. __ASSERT== __ACCU 1, DW#16#87000000
  209. // Check the DB-pointer pointed to by #DTDB
  210. L W [AR1, P#0.0]
  211. __ASSERT== __ACCU 1, 42 // DB-nr
  212. T #DBNR
  213. L D [AR1, P#2.0]
  214. __ASSERT== __ACCU 1, DW#16#84000020
  215. LAR2
  216. AUF DB [#DBNR]
  217. // Check the actual values
  218. L D [AR2, P#0.0]
  219. __ASSERT== __ACCU 1, DW#16#87654321
  220. L D [AR2, P#4.0]
  221. __ASSERT== __ACCU 1, DW#16#DDCCBBAA
  222. END_FUNCTION
  223. FUNCTION_BLOCK FB 10
  224. VAR_INPUT
  225. DUMMYIN : INT;
  226. DTVAR : DATE_AND_TIME;
  227. END_VAR
  228. BEGIN
  229. CALL FC 11 (
  230. DTIN := #DTVAR,
  231. )
  232. END_FUNCTION_BLOCK
  233. FUNCTION FC 11 : VOID
  234. VAR_INPUT
  235. DTIN : DATE_AND_TIME;
  236. END_VAR
  237. VAR_TEMP
  238. DBNR : INT;
  239. END_VAR
  240. BEGIN
  241. // Load #DTDB into AR1
  242. L P##DTIN
  243. LAR1
  244. UD DW#16#FF000000
  245. __ASSERT== __ACCU 1, DW#16#87000000
  246. // Check the DB-pointer pointed to by #DTIN
  247. L W [AR1, P#0.0]
  248. __ASSERT== __ACCU 1, 10 // DB-nr
  249. T #DBNR
  250. L D [AR1, P#2.0]
  251. __ASSERT== __ACCU 1, DW#16#84000010
  252. LAR2
  253. AUF DB [#DBNR]
  254. // Check the actual values
  255. L D [AR2, P#0.0]
  256. __ASSERT== __ACCU 1, DW#16#87654321
  257. L D [AR2, P#4.0]
  258. __ASSERT== __ACCU 1, DW#16#DDCCBBAA
  259. END_FUNCTION
  260. DATA_BLOCK DB 10
  261. FB 10
  262. BEGIN
  263. END_DATA_BLOCK
  264. DATA_BLOCK DB 42
  265. STRUCT
  266. DUMMY1 : INT; // DBX 0.0
  267. DUMMY2 : INT; // DBX 2.0
  268. DTVAR1 : DATE_AND_TIME; // DBX 4.0
  269. DUMMY3 : INT; // DBX 12.0
  270. DTVAR2 : DATE_AND_TIME; // DBX 14.0
  271. DTVAR3 : DATE_AND_TIME; // DBX 22.0
  272. DTVAR4 : DATE_AND_TIME; // DBX 30.0
  273. ARR1 : ARRAY [1 .. 2] OF STRUCT
  274. V1 : INT; // DBX 38.0 / 42.0
  275. V2 : INT; // DBX 40.0 / 44.0
  276. END_STRUCT;
  277. END_STRUCT;
  278. BEGIN
  279. END_DATA_BLOCK
  280. FUNCTION FC 50 : POINTER
  281. VAR_INPUT
  282. FCPTR1 : POINTER;
  283. FCPTR2 : POINTER;
  284. FCPTR3 : POINTER;
  285. FCPTR4 : POINTER;
  286. FCPTR5 : POINTER;
  287. FCPTR6 : POINTER;
  288. FCPTR7 : POINTER;
  289. END_VAR
  290. VAR_OUTPUT
  291. FCOUTPTR1 : POINTER;
  292. END_VAR
  293. BEGIN
  294. L P##FCPTR1
  295. LAR1
  296. UD DW#16#FF000000
  297. __ASSERT== __ACCU 1, DW#16#87000000
  298. L W [AR1, P#0.0]
  299. __ASSERT== __ACCU 1, 50
  300. L D [AR1, P#2.0]
  301. __ASSERT== __ACCU 1, P#DBX 10.0
  302. L P##FCPTR2
  303. LAR1
  304. UD DW#16#FF000000
  305. __ASSERT== __ACCU 1, DW#16#87000000
  306. L W [AR1, P#0.0]
  307. __ASSERT== __ACCU 1, 50
  308. L D [AR1, P#2.0]
  309. __ASSERT== __ACCU 1, P#DBX 10.1
  310. L P##FCPTR3
  311. LAR1
  312. UD DW#16#FF000000
  313. __ASSERT== __ACCU 1, DW#16#87000000
  314. L W [AR1, P#0.0]
  315. __ASSERT== __ACCU 1, 0
  316. L D [AR1, P#2.0]
  317. __ASSERT== __ACCU 1, P#M 99.7
  318. L P##FCPTR4
  319. LAR1
  320. UD DW#16#FF000000
  321. __ASSERT== __ACCU 1, DW#16#87000000
  322. L W [AR1, P#0.0]
  323. __ASSERT== __ACCU 1, 0
  324. L D [AR1, P#2.0]
  325. __ASSERT== __ACCU 1, P#M 99.7
  326. L P##FCPTR5
  327. LAR1
  328. UD DW#16#FF000000
  329. __ASSERT== __ACCU 1, DW#16#87000000
  330. L W [AR1, P#0.0]
  331. __ASSERT== __ACCU 1, 0
  332. L D [AR1, P#2.0]
  333. __ASSERT== __ACCU 1, P#7.1
  334. L P##FCPTR6
  335. LAR1
  336. UD DW#16#FF000000
  337. __ASSERT== __ACCU 1, DW#16#87000000
  338. L W [AR1, P#0.0]
  339. __ASSERT== __ACCU 1, 1
  340. L D [AR1, P#2.0]
  341. __ASSERT== __ACCU 1, P#DBX 8.0
  342. L P##FCPTR7
  343. LAR1
  344. UD DW#16#FF000000
  345. __ASSERT== __ACCU 1, DW#16#87000000
  346. L W [AR1, P#0.0]
  347. __ASSERT== __ACCU 1, 0
  348. L D [AR1, P#2.0]
  349. UD DW#16#FF000000
  350. __ASSERT== __ACCU 1, DW#16#87000000
  351. L P##FCOUTPTR1
  352. LAR1
  353. UD DW#16#FF000000
  354. __ASSERT== __ACCU 1, DW#16#87000000
  355. L W [AR1, P#0.0]
  356. __ASSERT== __ACCU 1, 0
  357. L D [AR1, P#2.0]
  358. __ASSERT== __ACCU 1, P#M 98.7
  359. L P##RET_VAL
  360. LAR1
  361. UD DW#16#FF000000
  362. __ASSERT== __ACCU 1, DW#16#87000000
  363. L W [AR1, P#0.0]
  364. __ASSERT== __ACCU 1, 0
  365. L D [AR1, P#2.0]
  366. __ASSERT== __ACCU 1, P#A 97.6
  367. END_FUNCTION
  368. FUNCTION_BLOCK FB 50
  369. VAR_INPUT
  370. FBPTR1 : POINTER;
  371. FBPTR2 : POINTER;
  372. FBPTR3 : POINTER;
  373. FBPTR4 : POINTER;
  374. FBPTR5 : POINTER;
  375. FBPTR6 : POINTER;
  376. FBPTR7 : POINTER;
  377. END_VAR
  378. BEGIN
  379. L P##FBPTR1
  380. LAR1
  381. UD DW#16#FF000000
  382. __ASSERT== __ACCU 1, DW#16#85000000
  383. L W [AR1, P#0.0]
  384. __ASSERT== __ACCU 1, 50
  385. L D [AR1, P#2.0]
  386. __ASSERT== __ACCU 1, P#DBX 10.0
  387. L P##FBPTR2
  388. LAR1
  389. UD DW#16#FF000000
  390. __ASSERT== __ACCU 1, DW#16#85000000
  391. L W [AR1, P#0.0]
  392. __ASSERT== __ACCU 1, 50
  393. L D [AR1, P#2.0]
  394. __ASSERT== __ACCU 1, P#DBX 10.1
  395. L P##FBPTR3
  396. LAR1
  397. UD DW#16#FF000000
  398. __ASSERT== __ACCU 1, DW#16#85000000
  399. L W [AR1, P#0.0]
  400. __ASSERT== __ACCU 1, 0
  401. L D [AR1, P#2.0]
  402. __ASSERT== __ACCU 1, P#M 99.7
  403. L P##FBPTR4
  404. LAR1
  405. UD DW#16#FF000000
  406. __ASSERT== __ACCU 1, DW#16#85000000
  407. L W [AR1, P#0.0]
  408. __ASSERT== __ACCU 1, 0
  409. L D [AR1, P#2.0]
  410. __ASSERT== __ACCU 1, P#M 99.7
  411. L P##FBPTR5
  412. LAR1
  413. UD DW#16#FF000000
  414. __ASSERT== __ACCU 1, DW#16#85000000
  415. L W [AR1, P#0.0]
  416. __ASSERT== __ACCU 1, 0
  417. L D [AR1, P#2.0]
  418. __ASSERT== __ACCU 1, P#7.1
  419. L P##FBPTR6
  420. LAR1
  421. UD DW#16#FF000000
  422. __ASSERT== __ACCU 1, DW#16#85000000
  423. L W [AR1, P#0.0]
  424. __ASSERT== __ACCU 1, 1
  425. L D [AR1, P#2.0]
  426. __ASSERT== __ACCU 1, P#DBX 8.0
  427. L P##FBPTR7
  428. LAR1
  429. UD DW#16#FF000000
  430. __ASSERT== __ACCU 1, DW#16#85000000
  431. L W [AR1, P#0.0]
  432. __ASSERT== __ACCU 1, 0
  433. L D [AR1, P#2.0]
  434. UD DW#16#FF000000
  435. __ASSERT== __ACCU 1, DW#16#87000000
  436. END_FUNCTION_BLOCK
  437. DATA_BLOCK DB 50
  438. FB 50
  439. BEGIN
  440. END_DATA_BLOCK
  441. FUNCTION FC 60 : VOID
  442. VAR_INPUT
  443. FC_DTIMM_0 : DATE_AND_TIME;
  444. END_VAR
  445. BEGIN
  446. // Load #FC_DTIMM_0 into AR1
  447. L P##FC_DTIMM_0
  448. LAR1
  449. UD DW#16#FF000000
  450. __ASSERT== __ACCU 1, DW#16#87000000
  451. // Check the DB-pointer pointed to by #FC_DTIMM_0
  452. L W [AR1, P#0.0]
  453. __ASSERT== __ACCU 1, 0 // DB-nr
  454. L D [AR1, P#2.0]
  455. LAR1
  456. UD DW#16#FF000000
  457. __ASSERT== __ACCU 1, DW#16#87000000
  458. // Check the actual values
  459. L D [AR1, P#0.0]
  460. __ASSERT== __ACCU 1, DW#16#98020316
  461. L D [AR1, P#4.0]
  462. __ASSERT== __ACCU 1, DW#16#17202113
  463. END_FUNCTION
  464. FUNCTION_BLOCK FB 60
  465. VAR_INPUT
  466. FB_DTIMM_0 : DATE_AND_TIME;
  467. END_VAR
  468. BEGIN
  469. // Load #FB_DTIMM_0 into AR1
  470. L P##FB_DTIMM_0
  471. LAR1
  472. UD DW#16#FF000000
  473. __ASSERT== __ACCU 1, DW#16#85000000
  474. // Check the actual values
  475. L D [AR1, P#0.0]
  476. __ASSERT== __ACCU 1, DW#16#98020316
  477. L D [AR1, P#4.0]
  478. __ASSERT== __ACCU 1, DW#16#17202113
  479. END_FUNCTION_BLOCK
  480. DATA_BLOCK DB 60
  481. FB 60
  482. BEGIN
  483. END_DATA_BLOCK
  484. FUNCTION FC 70 : VOID
  485. VAR_INPUT
  486. FCP1 : POINTER;
  487. END_VAR
  488. BEGIN
  489. // Load #FCP1 into AR1
  490. L P##FCP1
  491. LAR1
  492. UD DW#16#FF000000
  493. __ASSERT== __ACCU 1, DW#16#87000000
  494. L W [AR1, P#0.0]
  495. __ASSERT== __ACCU 1, 42 // DB-nr
  496. L D [AR1, P#2.0]
  497. __ASSERT== __ACCU 1, P#DBX 38.0
  498. END_FUNCTION
  499. FUNCTION_BLOCK FB 70
  500. VAR_INPUT
  501. FBP1 : POINTER;
  502. END_VAR
  503. BEGIN
  504. // Load #FBP1 into AR1
  505. L P##FBP1
  506. LAR1
  507. __ASSERT== __ACCU 1, DW#16#85000000
  508. L W [AR1, P#0.0]
  509. __ASSERT== __ACCU 1, 42 // DB-nr
  510. L D [AR1, P#2.0]
  511. __ASSERT== __ACCU 1, P#DBX 38.0
  512. END_FUNCTION_BLOCK
  513. DATA_BLOCK DB 70
  514. FB 70
  515. BEGIN
  516. END_DATA_BLOCK