prjbrook

arithmeticB.asm 1802 arith routines

Apr 3rd, 2020
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.76 KB | None | 0 0
  1. ;Tested all the additions, add, adi, adc and adci various ways with 8 bits Worked.
  2. ; ..Sat Apr 4 15:45:07 NZDT 2020
  3. ;Tested all shifts. Simulation worked. Tested some in real 1802.Worked.Fri Apr 3 13:57:52 NZDT 202
  4.  
  5. ;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.
  6. ;Now trying left shifts.
  7. ;Thu Apr 2 12:37:43 NZDT 2020. Now trying with shiftsA.asm to practice shifts and first loops.
  8. ;New tack. Logic. Wed Apr 1 12:38:35 NZDT 202. logicA.asm. Logic rountines using and,or,xor all work below.
  9. ;Tue Mar 31 14:48:41 NZDT 2020 scartB.asm. Now trying to call a subroutine inside another one.
  10. buf equ 007
  11. buf0 equ 007
  12. ctr equ 008
  13. buf1 equ 008
  14. buf2 equ 009
  15. START ORG 0
  16. ; seq
  17. ; req
  18. ; seq
  19. ldi $03 ;careful, we have some nops up there.
  20. phi 2 ;R2 is stack pointer
  21. ldi $ff
  22. plo 2 ;R2=stack pointer now points to $00ff
  23. sex 2 ;X now pnts to R2, the stack pointer. 00ff
  24.  
  25. ldi $03 ;note, this pointer gets changed by different routines below.
  26. phi 7 ;R7 is buf0 and buf
  27. ldi $40
  28. plo 7 ;R7 contains arbitrary pointer $340
  29.  
  30. ldi $03 ;note, this pointer gets changed by different routines below.
  31. phi 8 ;R8 is buf1 and ctr
  32. ldi $50
  33. plo 8 ;R8 contains arbitrary pointer $350
  34.  
  35. ldi $03 ;changes.
  36. phi 9 ;buf2
  37. ldi $60
  38. plo 9 ;R9 contains aritrary pointer $360
  39.  
  40. ldi HIGH(main)
  41. phi 3
  42. ldi LOW(main)
  43. plo 3 ;R3 now points to main; becomes main prog counter.
  44.  
  45. ldi HIGH(callr)
  46. phi 4
  47. ldi LOW(callr)
  48. plo 4 ;r4 now contains pointer to callr
  49. ldi HIGH(retr)
  50. phi 5
  51. ldi LOW(retr)
  52. plo 5 ;r5 now contains pointer to callr
  53.  
  54. sep 3 ;sp points to main
  55. nop ;never get here
  56.  
  57. main
  58. ldi $02
  59. phi 6
  60. ldi $34
  61. plo 6 ;just to see something in there,r6, for debugging.
  62. ldi $f1 ;dummy write just to see we got here ok
  63. str 6
  64. ;88888888888888888888888888888888888888888888888888888888888888888888888888888888888
  65. sep 4 ;************main prog*********
  66. dw arithADCI
  67. ; dw arithADC
  68. ; dw arithADI
  69. ; dw arithADD
  70. ; dw tryDF
  71. ; dw shiftloopSHLC
  72. ; dw shiftloopSHL ;worked Fri Apr 3 13:43:11 NZDT 2020
  73. ; dw shiftloopSHRC ;works OK Fri Apr 3 13:30:40 NZDT 2020
  74. ; dw shiftloop
  75. ; dw do_shr2 ;play with shift right and loops
  76. ; dw do_shr ;play with shift right
  77. idl
  78. ; dw shifts
  79. ; dw testLogic
  80. idl ;stop
  81. ;-----main code below here not used --------------
  82. sep 4
  83. dw sub1 ;call sub1
  84.  
  85. ldi $ee ;dummy write just to see we got here ok
  86. inc 7
  87. str 7
  88.  
  89. sep 4
  90. dw sub2 ;call sub2
  91.  
  92. ldi $dd ;dummy write just to see we got here ok
  93. inc 7
  94. str 7
  95.  
  96. idl ;finish
  97. exita
  98. sep 3
  99. callr ;code for call routine goes here. r4 is pointer.
  100. nop ;assume x=2 and r2 is stack pointer
  101. sex 2 ;in case x was changed by some other code. Point to stack with r2.
  102. ghi 6
  103. stxd
  104. glo 6
  105. stxd ;r6 now pushed onto stack
  106. ghi 3
  107. phi 6
  108. glo 3
  109. plo 6 ;r3 now saved in r6. NB r6 ponts just past calling sep
  110. lda 6 ;get first byte after calling sep
  111. phi 3
  112. lda 6
  113. plo 3 ;now r3 points to called subroutine
  114. br exita ;branch to entry pnt of callr. So r4 pnts to callr, for other calls. Brilliant.
  115.  
  116. ; sep 3 ;jump to new subroutine
  117.  
  118. exitr
  119. sep 3
  120. retr ;code for return subroutine goes here. r5 is pointer.
  121. nop ;come here after subroutine over
  122. ghi 6
  123. phi 3
  124. glo 6
  125. plo 3 ;r6 copied into r3. Soon to be PC
  126. sex 2 ;point to stack, maybe unnecessary. Put in anyway.
  127. inc 2 ;to point to old r6
  128. ldxa ;get stacked low byte
  129. plo 6
  130. ldx
  131. phi 6 ;now old r6 restored and stack pointer ok
  132. br exitr
  133. ; sep 3 ;go back to main program.
  134. ;---------------------------------------New subs go below here--------
  135. testLogic ;tested or,xor,and. All worked as expected. Next do immediate cases.
  136. ldi $00
  137. phi 8
  138. ldi $C0
  139. plo 8
  140. sex 8 ;x now points to r8 = $090
  141. do_or
  142. ldi $a5
  143. or
  144. str 7
  145. do_xor
  146. ldi $a5
  147. xor
  148. inc 7
  149. str 7
  150. do_and
  151. ldi $a5
  152. and
  153. inc 7
  154. str 7
  155. do_ori
  156. ldi $a5
  157. ori $93
  158. inc 7
  159. str 7
  160. do_xri
  161. ldi $a5
  162. xri $93
  163. inc 7
  164. str 7
  165. do_ani
  166. ldi $a5
  167. ani $93
  168. inc 7
  169. str 7
  170.  
  171. sep 5 ;return with $a5 OR M(RX)
  172.  
  173.  
  174. sub1
  175. inc 7
  176. ldi $11
  177. str 7
  178. sep 5 ;all returns go via retr that's pointed to by r5
  179. sub2
  180. inc 7
  181. ldi $22
  182. str 7
  183. sep 4
  184. dw sub3
  185. sep 5
  186.  
  187. sub3
  188. inc 7
  189. ldi $33
  190. str 7
  191. sep 5
  192. ;-----now start on shifts-----------------------
  193. shifts
  194. ldi $04 ;going to loop 4 times
  195. plo 8 ;r8 = ctr
  196. up
  197. glo 8 ;D=acc gets ctr
  198. str 7 ;write ctr to mem
  199. inc 7 ;for next write
  200.  
  201. dec 8 ;ctr = ctr-1
  202. glo 8 ;check if ctr is 0
  203. bnz up ;no loop again
  204. idl ;loop finished
  205. do_shr
  206. ldi $5a
  207. shr
  208. str 7
  209. shr
  210. inc 7
  211. str 7
  212. stxd
  213. nop
  214. ldxa ;trying to play with stack. Leave tidy.
  215. sep 5 ;return
  216.  
  217. do_shr2 ;trying to use counter.
  218. ldi $08
  219. plo 8 ;r8 is counter
  220. ldi $a5 ;arbitrary value
  221. stxd ;save it
  222. loop1
  223. ldxa ;get acc back
  224. shr
  225. str 7
  226. inc 7 ;put copy into memeory to inspect
  227. stxd ;put back onto stack new, shifted, value.
  228. dec 8 ;dec counter
  229. glo 8 ;check on ctr
  230. bnz loop1
  231. sep 5 ;all over after 8 loops
  232. ; idl
  233. ;Better go, hopefully, with shifts and loops.
  234. shiftloop
  235. ldi $08
  236. plo ctr
  237. ldi $a5 ;arbitrary
  238. str buf
  239. inc buf ;for next insertion
  240. up0 shr ;**testing this, really**
  241. str buf
  242.  
  243. ldi $80 ;proxy for zero
  244. bnf down0 ;if DF=0 print it
  245. ldi $81 ;proxy for one. Come here if DF=1
  246. down0
  247. str buf2 ;store DF flag in buf2, either 1=81 or 0=80
  248. inc buf2
  249. dec ctr
  250. glo ctr
  251. bz getout
  252.  
  253. lda buf ;get shifted byte back from storage
  254. br up0 ;repeat 8 times. Then inspect bufs in memory
  255. getout
  256. sep 5 ;all over
  257. ;````````````````````````````````````````````same as above but for SHRC=RSHR``````
  258. shiftloopSHRC ;testing "shift right with carry", page 24 RCA book.
  259. ldi $08
  260. plo ctr
  261. ldi $f0 ;arbitrary
  262. str buf
  263. inc buf ;for next insertion
  264. up1
  265. shrc
  266. ; shr ;**testing this, really**
  267. str buf
  268.  
  269. ldi $80 ;proxy for zero
  270. bnf down1 ;if DF=0 print it
  271. ldi $81 ;proxy for one. Come here if DF=1
  272. down1
  273. str buf2 ;store DF flag in buf2, either 1=81 or 0=80
  274. inc buf2
  275. dec ctr
  276. glo ctr
  277. bz getout1
  278.  
  279. lda buf ;get shifted byte back from storage
  280. br up1 ;repeat 8 times. Then inspect bufs in memory
  281. getout1
  282. sep 5 ;all over
  283.  
  284. ;````````````````````````````````````````````same as above but for SHL``````
  285. PAGE
  286. shiftloopSHL ;testing "shift left", page 24 RCA book.
  287. ldi $08
  288. plo ctr
  289. ldi $a5 ;arbitrary
  290. str buf
  291. inc buf ;for next insertion
  292. up2
  293. shl
  294. ; shrc
  295. ; shr ;**testing this, really**
  296. str buf
  297.  
  298. ldi $80 ;proxy for zero
  299. bnf down2 ;if DF=0 print it
  300. ldi $81 ;proxy for one. Come here if DF=1
  301. down2
  302. str buf2 ;store DF flag in buf2, either 1=81 or 0=80
  303. inc buf2
  304. dec ctr
  305. glo ctr
  306. bz getout2
  307.  
  308. lda buf ;get shifted byte back from storage
  309. br up2 ;repeat 8 times. Then inspect bufs in memory
  310. getout2
  311. sep 5 ;all over
  312.  
  313. shiftloopSHLC ;testing "shift left with carry ", page 25 RCA book.
  314. ldi $08
  315. plo ctr
  316. ldi $a5 ;arbitrary
  317. str buf
  318. inc buf ;for next insertion
  319. up3
  320. shlc
  321. ; shl
  322. ; shrc
  323. ; shr ;**testing this, really**
  324. str buf
  325.  
  326. ldi $80 ;proxy for zero
  327. bnf down3 ;if DF=0 print it
  328. ldi $81 ;proxy for one. Come here if DF=1
  329. down3
  330. str buf2 ;store DF flag in buf2, either 1=81 or 0=80
  331. inc buf2
  332. dec ctr
  333. glo ctr
  334. bz getout3
  335.  
  336. lda buf ;get shifted byte back from storage
  337. br up3 ;repeat 8 times. Then inspect bufs in memory
  338. getout3
  339. sep 5
  340. ;======================================arith routines=================
  341. arithADD ;for this r7,8,9 at $340,50,60 resp
  342. sex 7 ;x pints to r7=$340
  343. ldxa ;get byte stored in $340
  344. add ;(buf0)+(buf0+1) -> DF
  345. str 9
  346. inc 9 ;for next store
  347. ldi $80 ;proxy for zero in DF
  348. bnf downADD ;DF =0?, go down0
  349. ldi $81 ;pretend one=DF
  350. downADD
  351. str 9 ;put DF flag = carry beside sum
  352.  
  353. arithADI
  354. sex 7
  355. ldx ;get byte in $340
  356. adi $84 ;add arbitrary immediate
  357. str 9
  358. inc 9
  359. ldi $80
  360. bnf downADI
  361. ldi $81
  362. downADI
  363. str 9
  364.  
  365. arithADC
  366. testCarry
  367. ldi $ff
  368. shr
  369. ; ldi $00
  370. shr
  371. sex 7 ;x pints to r7=$340
  372. ldxa ;get byte stored in $340
  373. adc ;(buf0)+(buf0+1) -> DF
  374. str 9
  375. inc 9 ;for next store
  376. ldi $80 ;proxy for zero in DF
  377. bnf downADDc ;DF =0?, go down0
  378. ldi $81 ;pretend one=DF
  379. downADDc
  380. str 9 ;put DF flag = carry beside sum
  381.  
  382. arithADCI
  383. testCarryADCI
  384. ldi $ff
  385. shr
  386. ; ldi $00
  387. shr
  388. sex 7
  389. ldx ;get byte in $340
  390. adci $04 ;add arbitrary immediate
  391. str 9
  392. inc 9
  393. ldi $80
  394. bnf downADcI
  395. ldi $81
  396. downADcI
  397. str 9
  398.  
  399.  
  400. sep 5
  401.  
  402.  
  403.  
  404. ORG $340
  405. db $93,$94,$c5,$d2
  406. ;-------keep these nops for 1802 simulator and Arduino serial-------------
  407. ORG $3fb
  408. nop
  409. nop
  410. nop
  411. nop
  412. nop
  413. END
Advertisement
Add Comment
Please, Sign In to add comment