pointer.awl 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602
  1. ORGANIZATION_BLOCK OB 1
  2. BEGIN
  3. // Check pointer immediates
  4. L P#10.6
  5. __ASSERT== __ACCU 1, DW#16#00000056
  6. L P#P 1.1
  7. __ASSERT== __ACCU 1, DW#16#80000009
  8. L P#E 2.1
  9. __ASSERT== __ACCU 1, DW#16#81000011
  10. L P#A 3.1
  11. __ASSERT== __ACCU 1, DW#16#82000019
  12. L P#M 4.1
  13. __ASSERT== __ACCU 1, DW#16#83000021
  14. L P#L 5.1
  15. __ASSERT== __ACCU 1, DW#16#86000029
  16. // Test address register instructions
  17. L P#885.3
  18. LAR1
  19. L P#886.2
  20. LAR2
  21. __ASSERT== __ACCU 1, P#886.2
  22. __ASSERT== __ACCU 2, P#885.3
  23. __ASSERT== __AR 1, P#885.3
  24. __ASSERT== __AR 2, P#886.2
  25. +AR1 P#1.1
  26. __ASSERT== __AR 1, P#886.4
  27. +AR2 P#5.1
  28. __ASSERT== __AR 2, P#891.3
  29. LAR1 P#12.3
  30. LAR2 P#32.1
  31. __ASSERT== __AR 1, P#12.3
  32. __ASSERT== __AR 2, P#32.1
  33. L 111
  34. L 222
  35. TAR1
  36. __ASSERT== __ACCU 1, P#12.3
  37. __ASSERT== __ACCU 2, 222
  38. TAR2
  39. __ASSERT== __ACCU 1, P#32.1
  40. __ASSERT== __ACCU 2, P#12.3
  41. TAR1 LD 0
  42. TAR2 LD 4
  43. __ASSERT== LD 0, P#12.3
  44. __ASSERT== LD 4, P#32.1
  45. // Test indirect read
  46. L 0
  47. T MD 100
  48. T MD 104
  49. SET
  50. = M 100.0
  51. = M 100.2
  52. LAR1 P#100.0
  53. LAR2 P#104.0
  54. U M [AR1, P#0.0]
  55. __ASSERT== __STW VKE, 1
  56. U M [AR1, P#0.1]
  57. __ASSERT== __STW VKE, 0
  58. U M [AR1, P#0.2]
  59. __ASSERT== __STW VKE, 1
  60. U M [AR1, P#0.3]
  61. __ASSERT== __STW VKE, 0
  62. U M [AR1, P#1.0]
  63. __ASSERT== __STW VKE, 0
  64. U M [AR2, P#0.0]
  65. __ASSERT== __STW VKE, 0
  66. LAR1 P#100.1
  67. U M [AR1, P#0.0]
  68. __ASSERT== __STW VKE, 0
  69. U M [AR1, P#0.1]
  70. __ASSERT== __STW VKE, 1
  71. L P#100.0
  72. T LD 0
  73. U M [LD 0]
  74. __ASSERT== __STW VKE, 1
  75. L P#100.1
  76. T LD 0
  77. U M [LD 0]
  78. __ASSERT== __STW VKE, 0
  79. L P#100.0
  80. T LD 0
  81. L MD [LD 0]
  82. __ASSERT== __ACCU 1, DW#16#05000000
  83. LAR1 P#M 100.0
  84. U [AR1, P#0.0]
  85. __ASSERT== __STW VKE, 1
  86. U [AR1, P#0.1]
  87. __ASSERT== __STW VKE, 0
  88. U [AR1, P#0.2]
  89. __ASSERT== __STW VKE, 1
  90. U [AR1, P#0.3]
  91. __ASSERT== __STW VKE, 0
  92. LAR1 P#M 100.0
  93. L B [AR1, P#0.0]
  94. __ASSERT== __ACCU 1, DW#16#00000005
  95. L W [AR1, P#0.0]
  96. __ASSERT== __ACCU 1, DW#16#00000500
  97. L D [AR1, P#0.0]
  98. __ASSERT== __ACCU 1, DW#16#05000000
  99. // Test indirect write
  100. L 0
  101. T MD 100
  102. T MD 104
  103. SET
  104. = M 100.0
  105. = M 100.2
  106. LAR1 P#M 100.4
  107. = [AR1, P#0.0]
  108. = [AR1, P#0.1]
  109. L MD 100
  110. __ASSERT== __ACCU 1, DW#16#35000000
  111. LAR1 P#M 100.0
  112. L DW#16#ABCDEF12
  113. T D [AR1, P#0.0]
  114. L MD 100
  115. __ASSERT== __ACCU 1, DW#16#ABCDEF12
  116. T D [AR1, P#1.0]
  117. L MD 100
  118. __ASSERT== __ACCU 1, DW#16#ABABCDEF
  119. L P#100.0
  120. T LD 0
  121. L DW#16#98765432
  122. T MD [LD 0]
  123. L MD 100
  124. __ASSERT== __ACCU 1, DW#16#98765432
  125. LAR1 P#100.0
  126. L DW#16#12345678
  127. T MD [AR1, P#0.0]
  128. L MD 100
  129. __ASSERT== __ACCU 1, DW#16#12345678
  130. // Test indirect DB-open access
  131. AUF DB 1
  132. AUF DI 1
  133. L 2
  134. T LW 0
  135. AUF DB [LW 0]
  136. __ASSERT== DBNO, 2
  137. AUF DI [LW 0]
  138. __ASSERT== DINO, 2
  139. // Indirect counter access
  140. L 10
  141. T LW 0
  142. L Z [LW 0]
  143. __ASSERT== __ACCU 1, 0
  144. SET
  145. ZV Z 10
  146. CLR
  147. ZV Z [LW 0]
  148. L Z [LW 0]
  149. __ASSERT== __ACCU 1, 1
  150. // Indirect timer access
  151. L 10
  152. T LW 0
  153. L T [LW 0]
  154. __ASSERT== __ACCU 1, 0
  155. SET
  156. L W#16#0999
  157. SI T 10
  158. __SLEEP 50
  159. L T [LW 0]
  160. __ASSERT<> __ACCU 1, 0
  161. CLR
  162. L W#16#0999
  163. SI T [LW 0]
  164. L T [LW 0]
  165. __SLEEP 50
  166. L T [LW 0]
  167. __ASSERT== __ACCU 1, __ACCU 2
  168. CALL FB 1, DB 1 (
  169. IN_VAL_0 := 6666,
  170. IN_VAL_1 := 6767,
  171. ZERO_PTR_VAL := DW#16#0,
  172. ONE_PTR_VAL := DW#16#8,
  173. )
  174. CALL FC 1 (
  175. IN_VAL_0 := 5555,
  176. IN_VAL_1 := 5656,
  177. )
  178. CALL FC 2
  179. CALL SFC 46 // STOP CPU
  180. END_ORGANIZATION_BLOCK
  181. FUNCTION_BLOCK FB 1
  182. VAR_INPUT
  183. IN_VAL_0 : INT;
  184. IN_VAL_1 : INT;
  185. ZERO_PTR_VAL : DWORD;
  186. ONE_PTR_VAL : DWORD;
  187. END_VAR
  188. BEGIN
  189. L P##IN_VAL_0
  190. __ASSERT== __ACCU 1, DW#16#85000000
  191. L P##IN_VAL_1
  192. __ASSERT== __ACCU 1, DW#16#85000010
  193. L DW#16#11223344
  194. T MD 0
  195. L DW#16#55667788
  196. T MD 4
  197. L MD [#ZERO_PTR_VAL]
  198. __ASSERT== __ACCU 1, DW#16#11223344
  199. L MD [#ONE_PTR_VAL]
  200. __ASSERT== __ACCU 1, DW#16#22334455
  201. L DW#16#AABBCCDD
  202. T MD 1
  203. L 1
  204. T MW 12
  205. L 2
  206. T MW 14
  207. CALL FB 2, DB 2 (
  208. IN_VAL_0 := MD [#ONE_PTR_VAL],
  209. DB_VAL := DB [MW 14],
  210. FC_VAL := FC [MW 12],
  211. FB_VAL := FB [MW 12],
  212. )
  213. // Test all memory-indirect accesses
  214. AUF DB 1
  215. L P#8.0
  216. T LD 0
  217. U E [LD 0]
  218. = E [LD 0]
  219. U A [LD 0]
  220. = A [LD 0]
  221. U L [LD 0]
  222. = L [LD 0]
  223. U DIX [LD 0]
  224. = DIX [LD 0]
  225. U DBX [LD 0]
  226. = DBX [LD 0]
  227. L EB [LD 0]
  228. T EB [LD 0]
  229. L AB [LD 0]
  230. T AB [LD 0]
  231. L MB [LD 0]
  232. T MB [LD 0]
  233. L LB [LD 0]
  234. T LB [LD 0]
  235. L PEB [LD 0]
  236. T PAB [LD 0]
  237. L DBB [LD 0]
  238. T DBB [LD 0]
  239. L DIB [LD 0]
  240. T DIB [LD 0]
  241. L EW [LD 0]
  242. T EW [LD 0]
  243. L AW [LD 0]
  244. T AW [LD 0]
  245. L MW [LD 0]
  246. T MW [LD 0]
  247. L LW [LD 0]
  248. T LW [LD 0]
  249. L PEW [LD 0]
  250. T PAW [LD 0]
  251. L DBW [LD 0]
  252. T DBW [LD 0]
  253. L DIW [LD 0]
  254. T DIW [LD 0]
  255. L ED [LD 0]
  256. T ED [LD 0]
  257. L AD [LD 0]
  258. T AD [LD 0]
  259. L MD [LD 0]
  260. T MD [LD 0]
  261. L LD [LD 0]
  262. T LD [LD 0]
  263. L PED [LD 0]
  264. T PAD [LD 0]
  265. L DBD [LD 0]
  266. T DBD [LD 0]
  267. L DID [LD 0]
  268. T DID [LD 0]
  269. L 0
  270. T LW 0
  271. L T [LW 0]
  272. L Z [LW 0]
  273. // Test all register-indirect accesses
  274. AUF DB 1
  275. LAR1 P#8.0
  276. U E [AR1, P#0.0]
  277. = E [AR1, P#0.0]
  278. LAR1 P#E 8.0
  279. U [AR1, P#0.0]
  280. = [AR1, P#0.0]
  281. LAR1 P#8.0
  282. U A [AR1, P#0.0]
  283. = A [AR1, P#0.0]
  284. LAR1 P#A 8.0
  285. U [AR1, P#0.0]
  286. = [AR1, P#0.0]
  287. LAR1 P#8.0
  288. U M [AR1, P#0.0]
  289. = M [AR1, P#0.0]
  290. LAR1 P#M 8.0
  291. U [AR1, P#0.0]
  292. = [AR1, P#0.0]
  293. LAR1 P#8.0
  294. U L [AR1, P#0.0]
  295. = L [AR1, P#0.0]
  296. LAR1 P#L 8.0
  297. U [AR1, P#0.0]
  298. = [AR1, P#0.0]
  299. LAR1 P#8.0
  300. U DIX [AR1, P#0.0]
  301. = DIX [AR1, P#0.0]
  302. LAR1 P#DIX 8.0
  303. U [AR1, P#0.0]
  304. = [AR1, P#0.0]
  305. LAR1 P#8.0
  306. U DBX [AR1, P#0.0]
  307. = DBX [AR1, P#0.0]
  308. LAR1 P#DBX 8.0
  309. U [AR1, P#0.0]
  310. = [AR1, P#0.0]
  311. LAR1 P#8.0
  312. L EB [AR1, P#0.0]
  313. T EB [AR1, P#0.0]
  314. LAR1 P#E 8.0
  315. L B [AR1, P#0.0]
  316. T B [AR1, P#0.0]
  317. LAR1 P#8.0
  318. L AB [AR1, P#0.0]
  319. T AB [AR1, P#0.0]
  320. LAR1 P#A 8.0
  321. L B [AR1, P#0.0]
  322. T B [AR1, P#0.0]
  323. LAR1 P#8.0
  324. L MB [AR1, P#0.0]
  325. T MB [AR1, P#0.0]
  326. LAR1 P#M 8.0
  327. L B [AR1, P#0.0]
  328. T B [AR1, P#0.0]
  329. LAR1 P#8.0
  330. L LB [AR1, P#0.0]
  331. T LB [AR1, P#0.0]
  332. LAR1 P#L 8.0
  333. L B [AR1, P#0.0]
  334. T B [AR1, P#0.0]
  335. LAR1 P#8.0
  336. L PEB [AR1, P#0.0]
  337. T PAB [AR1, P#0.0]
  338. LAR1 P#P 8.0
  339. L B [AR1, P#0.0]
  340. T B [AR1, P#0.0]
  341. LAR1 P#8.0
  342. L DBB [AR1, P#0.0]
  343. T DBB [AR1, P#0.0]
  344. LAR1 P#DBX 8.0
  345. L B [AR1, P#0.0]
  346. T B [AR1, P#0.0]
  347. LAR1 P#8.0
  348. L DIB [AR1, P#0.0]
  349. T DIB [AR1, P#0.0]
  350. LAR1 P#DIX 8.0
  351. L B [AR1, P#0.0]
  352. T B [AR1, P#0.0]
  353. LAR1 P#8.0
  354. L EW [AR1, P#0.0]
  355. T EW [AR1, P#0.0]
  356. LAR1 P#E 8.0
  357. L W [AR1, P#0.0]
  358. T W [AR1, P#0.0]
  359. LAR1 P#8.0
  360. L AW [AR1, P#0.0]
  361. T AW [AR1, P#0.0]
  362. LAR1 P#A 8.0
  363. L W [AR1, P#0.0]
  364. T W [AR1, P#0.0]
  365. LAR1 P#8.0
  366. L MW [AR1, P#0.0]
  367. T MW [AR1, P#0.0]
  368. LAR1 P#M 8.0
  369. L W [AR1, P#0.0]
  370. T W [AR1, P#0.0]
  371. LAR1 P#8.0
  372. L LW [AR1, P#0.0]
  373. T LW [AR1, P#0.0]
  374. LAR1 P#L 8.0
  375. L W [AR1, P#0.0]
  376. T W [AR1, P#0.0]
  377. LAR1 P#8.0
  378. L PEW [AR1, P#0.0]
  379. T PAW [AR1, P#0.0]
  380. LAR1 P#P 8.0
  381. L W [AR1, P#0.0]
  382. T W [AR1, P#0.0]
  383. LAR1 P#8.0
  384. L DBW [AR1, P#0.0]
  385. T DBW [AR1, P#0.0]
  386. LAR1 P#DBX 8.0
  387. L W [AR1, P#0.0]
  388. T W [AR1, P#0.0]
  389. LAR1 P#8.0
  390. L DIW [AR1, P#0.0]
  391. T DIW [AR1, P#0.0]
  392. LAR1 P#DIX 8.0
  393. L W [AR1, P#0.0]
  394. T W [AR1, P#0.0]
  395. LAR1 P#8.0
  396. L ED [AR1, P#0.0]
  397. T ED [AR1, P#0.0]
  398. LAR1 P#E 8.0
  399. L D [AR1, P#0.0]
  400. T D [AR1, P#0.0]
  401. LAR1 P#8.0
  402. L AD [AR1, P#0.0]
  403. T AD [AR1, P#0.0]
  404. LAR1 P#A 8.0
  405. L D [AR1, P#0.0]
  406. T D [AR1, P#0.0]
  407. LAR1 P#8.0
  408. L MD [AR1, P#0.0]
  409. T MD [AR1, P#0.0]
  410. LAR1 P#M 8.0
  411. L D [AR1, P#0.0]
  412. T D [AR1, P#0.0]
  413. LAR1 P#8.0
  414. L LD [AR1, P#0.0]
  415. T LD [AR1, P#0.0]
  416. LAR1 P#L 8.0
  417. L D [AR1, P#0.0]
  418. T D [AR1, P#0.0]
  419. LAR1 P#8.0
  420. L PED [AR1, P#0.0]
  421. T PAD [AR1, P#0.0]
  422. LAR1 P#P 8.0
  423. L D [AR1, P#0.0]
  424. T D [AR1, P#0.0]
  425. LAR1 P#8.0
  426. L DBD [AR1, P#0.0]
  427. T DBD [AR1, P#0.0]
  428. LAR1 P#DBX 8.0
  429. L D [AR1, P#0.0]
  430. T D [AR1, P#0.0]
  431. LAR1 P#8.0
  432. L DID [AR1, P#0.0]
  433. T DID [AR1, P#0.0]
  434. LAR1 P#DIX 8.0
  435. L D [AR1, P#0.0]
  436. T D [AR1, P#0.0]
  437. END_FUNCTION_BLOCK
  438. FUNCTION_BLOCK FB 2
  439. VAR_INPUT
  440. IN_VAL_0 : DWORD;
  441. DB_VAL : BLOCK_DB;
  442. FC_VAL : BLOCK_FC;
  443. FB_VAL : BLOCK_FB;
  444. END_VAR
  445. BEGIN
  446. L #IN_VAL_0
  447. __ASSERT== __ACCU 1, DW#16#AABBCCDD
  448. AUF #DB_VAL
  449. L DBD 0
  450. L #IN_VAL_0
  451. __ASSERT== __ACCU 1, __ACCU 2
  452. END_FUNCTION_BLOCK
  453. FUNCTION FC 1 : VOID
  454. VAR_INPUT
  455. IN_VAL_0 : INT;
  456. IN_VAL_1 : INT;
  457. END_VAR
  458. BEGIN
  459. L P##IN_VAL_0
  460. UD DW#16#FFF80000
  461. __ASSERT== __ACCU 1, DW#16#87000000
  462. L P##IN_VAL_1
  463. UD DW#16#FFF80000
  464. __ASSERT== __ACCU 1, DW#16#87000000
  465. END_FUNCTION
  466. FUNCTION FC 2 : VOID
  467. TITLE =Extended address register instruction tests
  468. BEGIN
  469. // Open the data blocks
  470. AUF DB 3
  471. AUF DI 3
  472. // Initialize the memory areas
  473. L P#42.0
  474. T MD 0
  475. L P#43.0
  476. T LD 0
  477. L P#44.0
  478. T DBD 0
  479. L P#45.0
  480. T DID 4
  481. LAR2 P#46.0
  482. L P#47.0
  483. T MD 42
  484. // Test LAR1
  485. LAR1 MD 0
  486. __ASSERT== __AR 1, P#42.0
  487. LAR1 LD 0
  488. __ASSERT== __AR 1, P#43.0
  489. LAR1 DBD 0
  490. __ASSERT== __AR 1, P#44.0
  491. LAR1 DID 4
  492. __ASSERT== __AR 1, P#45.0
  493. LAR1 AR2
  494. __ASSERT== __AR 1, P#46.0
  495. // Test LAR2
  496. LAR2 MD 0
  497. __ASSERT== __AR 2, P#42.0
  498. LAR2 LD 0
  499. __ASSERT== __AR 2, P#43.0
  500. LAR2 DBD 0
  501. __ASSERT== __AR 2, P#44.0
  502. LAR2 DID 4
  503. __ASSERT== __AR 2, P#45.0
  504. // Test TAR1
  505. LAR1 P#142.7
  506. LAR2 P#143.1
  507. TAR1 MD 0
  508. __ASSERT== MD 0, P#142.7
  509. TAR1 LD 0
  510. __ASSERT== LD 0, P#142.7
  511. TAR1 DBD 0
  512. __ASSERT== DBD 0, P#142.7
  513. TAR1 DID 4
  514. __ASSERT== DID 4, P#142.7
  515. TAR1 AR2
  516. __ASSERT== __AR 2, P#142.7
  517. // Test TAR2
  518. LAR1 P#142.7
  519. LAR2 P#143.1
  520. TAR2 MD 0
  521. __ASSERT== MD 0, P#143.1
  522. TAR2 LD 0
  523. __ASSERT== LD 0, P#143.1
  524. TAR2 DBD 0
  525. __ASSERT== DBD 0, P#143.1
  526. TAR2 DID 4
  527. __ASSERT== DID 4, P#143.1
  528. // Test offset wrapping
  529. LAR1 P#41.7
  530. L MD [AR1,P#0.1]
  531. __ASSERT== __ACCU 1, P#47.0
  532. END_FUNCTION
  533. DATA_BLOCK DB 1
  534. FB 1
  535. BEGIN
  536. IN_VAL_0 := 88;
  537. IN_VAL_1 := 99;
  538. END_DATA_BLOCK
  539. DATA_BLOCK DB 2
  540. FB 2
  541. BEGIN
  542. END_DATA_BLOCK
  543. DATA_BLOCK DB 3
  544. STRUCT
  545. pointer_0 : DWORD;
  546. pointer_1 : DWORD;
  547. END_STRUCT;
  548. BEGIN
  549. pointer_0 := DW#16#0;
  550. pointer_1 := DW#16#0;
  551. END_DATA_BLOCK