prjbrook

arithmeticD.asm 1802 test prog for arith instructions

Apr 5th, 2020
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.72 KB | None | 0 0
  1. ; All arith instructions, 12 of them, all tested in simulator and on rfeal 1802. Working well Mon Apr 613:51:10 NZST 202
  2. ;Now looking at last lot of 4 subtraction instructions where d<-d-MRX. Mon Apr 6 13:27:18 NZST 202
  3. ;Tested first set of subtractions. Had some problems with SDBI but worked them out, I think.
  4. ;Tested all the additions, add, adi, adc and adci various ways with 8 bits Worked.
  5. ; ..Sat Apr 4 15:45:07 NZDT 2020
  6. ;Tested all shifts. Simulation worked. Tested some in real 1802.Worked.Fri Apr 3 13:57:52 NZDT 202
  7.  
  8. ;shiftloop worked well for shr. Fri Apr 3 13:17:44 NZDT 2020. next, in shiftsC.asm will try RSHR. Fri Apr 3 13:30:40 NZDT 2020 Worked.
  9. ;Now trying left shifts.
  10. ;Thu Apr 2 12:37:43 NZDT 2020. Now trying with shiftsA.asm to practice shifts and first loops.
  11. ;New tack. Logic. Wed Apr 1 12:38:35 NZDT 202. logicA.asm. Logic rountines using and,or,xor all work below.
  12. ;Tue Mar 31 14:48:41 NZDT 2020 scartB.asm. Now trying to call a subroutine inside another one.
  13. buf equ 007
  14. buf0 equ 007
  15. ctr equ 008
  16. buf1 equ 008
  17. buf2 equ 009
  18. START ORG 0
  19. ; seq
  20. ; req
  21. ; seq
  22. ldi $03 ;careful, we have some nops up there.
  23. phi 2 ;R2 is stack pointer
  24. ldi $ff
  25. plo 2 ;R2=stack pointer now points to $00ff
  26. sex 2 ;X now pnts to R2, the stack pointer. 00ff
  27.  
  28. ldi $03 ;note, this pointer gets changed by different routines below.
  29. phi 7 ;R7 is buf0 and buf
  30. ldi $40
  31. plo 7 ;R7 contains arbitrary pointer $340
  32.  
  33. ldi $03 ;note, this pointer gets changed by different routines below.
  34. phi 8 ;R8 is buf1 and ctr
  35. ldi $50
  36. plo 8 ;R8 contains arbitrary pointer $350
  37.  
  38. ldi $03 ;changes.
  39. phi 9 ;buf2
  40. ldi $60
  41. plo 9 ;R9 contains aritrary pointer $360
  42.  
  43. ldi HIGH(main)
  44. phi 3
  45. ldi LOW(main)
  46. plo 3 ;R3 now points to main; becomes main prog counter.
  47.  
  48. ldi HIGH(callr)
  49. phi 4
  50. ldi LOW(callr)
  51. plo 4 ;r4 now contains pointer to callr
  52. ldi HIGH(retr)
  53. phi 5
  54. ldi LOW(retr)
  55. plo 5 ;r5 now contains pointer to callr
  56.  
  57. sep 3 ;sp points to main
  58. nop ;never get here
  59.  
  60. main
  61. ldi $02
  62. phi 6
  63. ldi $34
  64. plo 6 ;just to see something in there,r6, for debugging.
  65. ldi $f1 ;dummy write just to see we got here ok
  66. str 6
  67. ;88888888888888888888888888888888888888888888888888888888888888888888888888888888888
  68. sep 4 ;************main prog*********
  69. dw arithSM
  70. ; dw arithSDBI
  71. ; dw arithSDB
  72. ; dw arithSDI
  73. ; dw arithSD
  74. ; dw arithADCI
  75. ; dw arithADC
  76. ; dw arithADI
  77. ; dw arithADD ;FIRST routine in arith adds below.
  78. ; dw tryDF
  79. ; dw shiftloopSHLC
  80. ; dw shiftloopSHL ;worked Fri Apr 3 13:43:11 NZDT 2020
  81. ; dw shiftloopSHRC ;works OK Fri Apr 3 13:30:40 NZDT 2020
  82. ; dw shiftloop
  83. ; dw do_shr2 ;play with shift right and loops
  84. ; dw do_shr ;play with shift right
  85. idl
  86. ; dw shifts
  87. ; dw testLogic
  88. idl ;stop
  89. ;-----main code below here not used --------------
  90. sep 4
  91. dw sub1 ;call sub1
  92.  
  93. ldi $ee ;dummy write just to see we got here ok
  94. inc 7
  95. str 7
  96.  
  97. sep 4
  98. dw sub2 ;call sub2
  99.  
  100. ldi $dd ;dummy write just to see we got here ok
  101. inc 7
  102. str 7
  103.  
  104. idl ;finish
  105. exita
  106. sep 3
  107. callr ;code for call routine goes here. r4 is pointer.
  108. nop ;assume x=2 and r2 is stack pointer
  109. sex 2 ;in case x was changed by some other code. Point to stack with r2.
  110. ghi 6
  111. stxd
  112. glo 6
  113. stxd ;r6 now pushed onto stack
  114. ghi 3
  115. phi 6
  116. glo 3
  117. plo 6 ;r3 now saved in r6. NB r6 ponts just past calling sep
  118. lda 6 ;get first byte after calling sep
  119. phi 3
  120. lda 6
  121. plo 3 ;now r3 points to called subroutine
  122. br exita ;branch to entry pnt of callr. So r4 pnts to callr, for other calls. Brilliant.
  123.  
  124. ; sep 3 ;jump to new subroutine
  125.  
  126. exitr
  127. sep 3
  128. retr ;code for return subroutine goes here. r5 is pointer.
  129. nop ;come here after subroutine over
  130. ghi 6
  131. phi 3
  132. glo 6
  133. plo 3 ;r6 copied into r3. Soon to be PC
  134. sex 2 ;point to stack, maybe unnecessary. Put in anyway.
  135. inc 2 ;to point to old r6
  136. ldxa ;get stacked low byte
  137. plo 6
  138. ldx
  139. phi 6 ;now old r6 restored and stack pointer ok
  140. br exitr
  141. ; sep 3 ;go back to main program.
  142. ;---------------------------------------New subs go below here--------
  143. testLogic ;tested or,xor,and. All worked as expected. Next do immediate cases.
  144. ldi $00
  145. phi 8
  146. ldi $C0
  147. plo 8
  148. sex 8 ;x now points to r8 = $090
  149. do_or
  150. ldi $a5
  151. or
  152. str 7
  153. do_xor
  154. ldi $a5
  155. xor
  156. inc 7
  157. str 7
  158. do_and
  159. ldi $a5
  160. and
  161. inc 7
  162. str 7
  163. do_ori
  164. ldi $a5
  165. ori $93
  166. inc 7
  167. str 7
  168. do_xri
  169. ldi $a5
  170. xri $93
  171. inc 7
  172. str 7
  173. do_ani
  174. ldi $a5
  175. ani $93
  176. inc 7
  177. str 7
  178.  
  179. sep 5 ;return with $a5 OR M(RX)
  180.  
  181.  
  182. sub1
  183. inc 7
  184. ldi $11
  185. str 7
  186. sep 5 ;all returns go via retr that's pointed to by r5
  187. sub2
  188. inc 7
  189. ldi $22
  190. str 7
  191. sep 4
  192. dw sub3
  193. sep 5
  194.  
  195. sub3
  196. inc 7
  197. ldi $33
  198. str 7
  199. sep 5
  200. ;-----now start on shifts-----------------------
  201. shifts
  202. ldi $04 ;going to loop 4 times
  203. plo 8 ;r8 = ctr
  204. up
  205. glo 8 ;D=acc gets ctr
  206. str 7 ;write ctr to mem
  207. inc 7 ;for next write
  208.  
  209. dec 8 ;ctr = ctr-1
  210. glo 8 ;check if ctr is 0
  211. bnz up ;no loop again
  212. idl ;loop finished
  213. do_shr
  214. ldi $5a
  215. shr
  216. str 7
  217. shr
  218. inc 7
  219. str 7
  220. stxd
  221. nop
  222. ldxa ;trying to play with stack. Leave tidy.
  223. sep 5 ;return
  224.  
  225. do_shr2 ;trying to use counter.
  226. ldi $08
  227. plo 8 ;r8 is counter
  228. ldi $a5 ;arbitrary value
  229. stxd ;save it
  230. loop1
  231. ldxa ;get acc back
  232. shr
  233. str 7
  234. inc 7 ;put copy into memeory to inspect
  235. stxd ;put back onto stack new, shifted, value.
  236. dec 8 ;dec counter
  237. glo 8 ;check on ctr
  238. bnz loop1
  239. sep 5 ;all over after 8 loops
  240. ; idl
  241. ;Better go, hopefully, with shifts and loops.
  242. shiftloop
  243. ldi $08
  244. plo ctr
  245. ldi $a5 ;arbitrary
  246. str buf
  247. inc buf ;for next insertion
  248. up0 shr ;**testing this, really**
  249. str buf
  250.  
  251. ldi $80 ;proxy for zero
  252. bnf down0 ;if DF=0 print it
  253. ldi $81 ;proxy for one. Come here if DF=1
  254. down0
  255. str buf2 ;store DF flag in buf2, either 1=81 or 0=80
  256. inc buf2
  257. dec ctr
  258. glo ctr
  259. bz getout
  260.  
  261. lda buf ;get shifted byte back from storage
  262. br up0 ;repeat 8 times. Then inspect bufs in memory
  263. getout
  264. sep 5 ;all over
  265. ;````````````````````````````````````````````same as above but for SHRC=RSHR``````
  266. shiftloopSHRC ;testing "shift right with carry", page 24 RCA book.
  267. ldi $08
  268. plo ctr
  269. ldi $f0 ;arbitrary
  270. str buf
  271. inc buf ;for next insertion
  272. up1
  273. shrc
  274. ; shr ;**testing this, really**
  275. str buf
  276.  
  277. ldi $80 ;proxy for zero
  278. bnf down1 ;if DF=0 print it
  279. ldi $81 ;proxy for one. Come here if DF=1
  280. down1
  281. str buf2 ;store DF flag in buf2, either 1=81 or 0=80
  282. inc buf2
  283. dec ctr
  284. glo ctr
  285. bz getout1
  286.  
  287. lda buf ;get shifted byte back from storage
  288. br up1 ;repeat 8 times. Then inspect bufs in memory
  289. getout1
  290. sep 5 ;all over
  291.  
  292. ;````````````````````````````````````````````same as above but for SHL``````
  293. PAGE
  294. shiftloopSHL ;testing "shift left", page 24 RCA book.
  295. ldi $08
  296. plo ctr
  297. ldi $a5 ;arbitrary
  298. str buf
  299. inc buf ;for next insertion
  300. up2
  301. shl
  302. ; shrc
  303. ; shr ;**testing this, really**
  304. str buf
  305.  
  306. ldi $80 ;proxy for zero
  307. bnf down2 ;if DF=0 print it
  308. ldi $81 ;proxy for one. Come here if DF=1
  309. down2
  310. str buf2 ;store DF flag in buf2, either 1=81 or 0=80
  311. inc buf2
  312. dec ctr
  313. glo ctr
  314. bz getout2
  315.  
  316. lda buf ;get shifted byte back from storage
  317. br up2 ;repeat 8 times. Then inspect bufs in memory
  318. getout2
  319. sep 5 ;all over
  320.  
  321. shiftloopSHLC ;testing "shift left with carry ", page 25 RCA book.
  322. ldi $08
  323. plo ctr
  324. ldi $a5 ;arbitrary
  325. str buf
  326. inc buf ;for next insertion
  327. up3
  328. shlc
  329. ; shl
  330. ; shrc
  331. ; shr ;**testing this, really**
  332. str buf
  333.  
  334. ldi $80 ;proxy for zero
  335. bnf down3 ;if DF=0 print it
  336. ldi $81 ;proxy for one. Come here if DF=1
  337. down3
  338. str buf2 ;store DF flag in buf2, either 1=81 or 0=80
  339. inc buf2
  340. dec ctr
  341. glo ctr
  342. bz getout3
  343.  
  344. lda buf ;get shifted byte back from storage
  345. br up3 ;repeat 8 times. Then inspect bufs in memory
  346. getout3
  347. sep 5
  348. ;======================================arith routines=====.Useful.
  349. ;one big routine for four instructions============
  350. arithADD ;for this r7,8,9 at $340,50,60 resp
  351. sex 7 ;x pints to r7=$340
  352. ldxa ;get byte stored in $340
  353. add ;(buf0)+(buf0+1) -> DF
  354. str 9
  355. inc 9 ;for next store
  356. ldi $80 ;proxy for zero in DF
  357. bnf downADD ;DF =0?, go down0
  358. ldi $81 ;pretend one=DF
  359. downADD
  360. str 9 ;put DF flag = carry beside sum
  361. inc 9
  362.  
  363. arithADI
  364. sex 7
  365. ldxa ;get byte in $340
  366. adi $84 ;add arbitrary immediate
  367. str 9
  368. inc 9
  369. ldi $80
  370. bnf downADI
  371. ldi $81
  372. downADI
  373. str 9
  374. inc 9
  375.  
  376. arithADC
  377. testCarry
  378. ldi $ff
  379. shr
  380. ; ldi $00
  381. shr
  382. sex 7 ;x pints to r7=$340
  383. ldxa ;get byte stored in $340
  384. adc ;(buf0)+(buf0+1) -> DF
  385. str 9
  386. inc 9 ;for next store
  387. ldi $80 ;proxy for zero in DF
  388. bnf downADDc ;DF =0?, go down0
  389. ldi $81 ;pretend one=DF
  390. downADDc
  391. str 9 ;put DF flag = carry beside sum
  392. inc 9
  393.  
  394. arithADCI
  395. testCarryADCI
  396. ldi $ff
  397. shr
  398. ; ldi $00
  399. shr
  400. sex 7
  401. ldxa ;get byte in $340
  402. adci $04 ;add arbitrary immediate
  403. str 9
  404. inc 9
  405. ldi $80
  406. bnf downADcI
  407. ldi $81
  408. downADcI
  409. str 9
  410. inc 9
  411. ;-------------------------------------------------------------------
  412. ;Now doing subtractions. Sun Apr 5 13:40:19 NZST 202
  413. arithSD ;for this r7,8,9 at $340,50,60 resp
  414. sex 7 ;x pints to r7=$340
  415. ldxa ;get byte stored in $340
  416. sd ;(buf0+1)-(buf0) -> DF
  417. str 9
  418. inc 9 ;for next store
  419. ldi $80 ;proxy for zero in DF
  420. bnf downSD ;DF =0?, go down0
  421. ldi $81 ;pretend one=DF
  422. downSD
  423. str 9 ;put DF flag = carry beside sum
  424. inc 9
  425.  
  426. arithSDI
  427. sex 7
  428. ldxa ;get byte in $340
  429. sdi $84 ;subtract D from arbitrary immediate
  430. str 9
  431. inc 9
  432. ldi $80
  433. bnf downSDI
  434. ldi $81
  435. downSDI
  436. str 9
  437. inc 9
  438.  
  439. arithSDB
  440. testCarrySDB
  441. ldi $ff
  442. shr
  443. ldi $00
  444. shr
  445. sex 7 ;x pints to r7=$340
  446. ldxa ;get byte stored in $340
  447. sdb ;
  448. str 9
  449. inc 9 ;for next store
  450. ldi $80 ;proxy for zero in DF
  451. bnf downsdb ;DF =0?, go down0
  452. ldi $81 ;pretend one=DF
  453. downsdb
  454. str 9 ;put DF flag = carry beside sum
  455. inc 9
  456.  
  457. arithSDBI ;seems not to work on simulator
  458. testCarrySDBI
  459. ldi $ff
  460. shr
  461. ldi $00
  462. shr
  463. sex 7
  464. ldxa ;get byte in $340
  465. sdbi $34 ;subtract arbitrary immediate from D - NOT(DF)
  466. str 9
  467. inc 9
  468. ldi $80
  469. bnf downSDBI
  470. ldi $81
  471. downSDBI
  472. str 9
  473. inc 9
  474. ;ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss
  475. ;Now doing second set of subtractions. Mon Apr 6 13:27:18 NZST 2020
  476. arithSM ;for this r7,8,9 at $340,50,60 resp
  477. sex 7 ;x pints to r7=$340
  478. ldxa ;get byte stored in $340
  479. sm ;(buf0)-(buf0+1) -> DF
  480. str 9
  481. inc 9 ;for next store
  482. ldi $80 ;proxy for zero in DF
  483. bnf downSM ;DF =0?, go down0
  484. ldi $81 ;pretend one=DF
  485. downSM
  486. str 9 ;put DF flag = carry beside sum
  487. inc 9
  488.  
  489. arithSMI
  490. sex 7
  491. ldxa ;get byte in $340
  492. smi $84 ;subtract arbitrary immediate from D
  493. str 9
  494. inc 9
  495. ldi $80
  496. bnf downSMI
  497. ldi $81
  498. downSMI
  499. str 9
  500. inc 9
  501.  
  502. arithSMB
  503. testCarrySMB
  504. ldi $ff
  505. shr
  506. ldi $00
  507. shr
  508. sex 7 ;x pints to r7=$340
  509. ldxa ;get byte stored in $340
  510. smb ;
  511. str 9
  512. inc 9 ;for next store
  513. ldi $80 ;proxy for zero in DF
  514. bnf downsmb ;DF =0?, go down0
  515. ldi $81 ;pretend one=DF
  516. downsmb
  517. str 9 ;put DF flag = carry beside sum
  518. inc 9
  519.  
  520. arithSMBI
  521. testCarrySMBI
  522. ldi $ff
  523. shr
  524. ldi $00
  525. shr
  526. sex 7
  527. ldxa ;get byte in $340
  528. smbi $34 ;subtract arbitrary immediate from D - NOT(DF)
  529. str 9
  530. inc 9
  531. ldi $80
  532. bnf downSMBI
  533. ldi $81
  534. downSMBI
  535. str 9
  536. inc 9
  537.  
  538. sep 5
  539.  
  540. ORG $340
  541. db $82,$96,$c5,$a1,$0c
  542. ;-------keep these nops for 1802 simulator and Arduino serial-------------
  543. ORG $3fb
  544. nop
  545. nop
  546. nop
  547. nop
  548. nop
  549. END
Advertisement
Add Comment
Please, Sign In to add comment