prjbrook

logicA.asm for 1802. Testing logic instuctions.

Mar 31st, 2020
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.01 KB | None | 0 0
  1. ;New tack. Logic. Wed Apr 1 12:38:35 NZDT 202. logicA.asm. Logic rountines using and,or,xor all work below.
  2. ;Tue Mar 31 14:48:41 NZDT 2020 scartB.asm. Now trying to call a subroutine inside another one.
  3.  
  4. START ORG 0
  5. ; seq
  6. ; req
  7. ; seq
  8. ldi $00
  9. phi 2 ;R2 is stack pointer
  10. ldi $ff
  11. plo 2 ;R2=stack pointer now points to $00ff
  12. sex 2 ;X now pnts to R2, the stack pointer. 00ff
  13. ldi $00
  14. phi 7
  15. ldi $b0
  16. plo 7 ;R7 contains aritrary pointer $0b0
  17.  
  18. ldi HIGH(main)
  19. phi 3
  20. ldi LOW(main)
  21. plo 3 ;R3 now points to main; becomes main prog counter.
  22.  
  23. ldi HIGH(callr)
  24. phi 4
  25. ldi LOW(callr)
  26. plo 4 ;r4 now contains pointer to callr
  27. ldi HIGH(retr)
  28. phi 5
  29. ldi LOW(retr)
  30. plo 5 ;r5 now contains pointer to callr
  31.  
  32. sep 3 ;sp points to main
  33. nop ;never get here
  34.  
  35. main
  36. ldi $12
  37. phi 6
  38. ldi $34
  39. plo 6 ;just to see something in there,r6, for debugging.
  40. ldi $f1 ;dummy write just to see we got here ok
  41. str 6
  42.  
  43. sep 4
  44. dw testLogic
  45. idl ;stop
  46. ;-----main code below here not used --------------
  47. sep 4
  48. dw sub1 ;call sub1
  49.  
  50. ldi $ee ;dummy write just to see we got here ok
  51. inc 7
  52. str 7
  53.  
  54. sep 4
  55. dw sub2 ;call sub2
  56.  
  57. ldi $dd ;dummy write just to see we got here ok
  58. inc 7
  59. str 7
  60.  
  61. idl ;finish
  62. exita
  63. sep 3
  64. callr ;code for call routine goes here. r4 is pointer.
  65. nop ;assume x=2 and r2 is stack pointer
  66. sex 2 ;in case x was changed by some other code. Point to stack with r2.
  67. ghi 6
  68. stxd
  69. glo 6
  70. stxd ;r6 now pushed onto stack
  71. ghi 3
  72. phi 6
  73. glo 3
  74. plo 6 ;r3 now saved in r6. NB r6 ponts just past calling sep
  75. lda 6 ;get first byte after calling sep
  76. phi 3
  77. lda 6
  78. plo 3 ;now r3 points to called subroutine
  79. br exita ;branch to entry pnt of callr. So r4 pnts to callr, for other calls. Brilliant.
  80.  
  81. ; sep 3 ;jump to new subroutine
  82.  
  83. exitr
  84. sep 3
  85. retr ;code for return subroutine goes here. r5 is pointer.
  86. nop ;come here after subroutine over
  87. ghi 6
  88. phi 3
  89. glo 6
  90. plo 3 ;r6 copied into r3. Soon to be PC
  91. sex 2 ;point to stack, maybe unnecessary. Put in anyway.
  92. inc 2 ;to point to old r6
  93. ldxa ;get stacked low byte
  94. plo 6
  95. ldx
  96. phi 6 ;now old r6 restored and stack pointer ok
  97. br exitr
  98. ; sep 3 ;go back to main program.
  99. ;---------------------------------------New subs go below here--------
  100. testLogic ;tested or,xor,and. All worked as expected. Next do immediate cases.
  101. ldi $00
  102. phi 8
  103. ldi $C0
  104. plo 8
  105. sex 8 ;x now points to r8 = $090
  106. do_or
  107. ldi $a5
  108. or
  109. str 7
  110. do_xor
  111. ldi $a5
  112. xor
  113. inc 7
  114. str 7
  115. do_and
  116. ldi $a5
  117. and
  118. inc 7
  119. str 7
  120. do_ori
  121. ldi $a5
  122. ori $93
  123. inc 7
  124. str 7
  125. do_xri
  126. ldi $a5
  127. xri $93
  128. inc 7
  129. str 7
  130. do_ani
  131. ldi $a5
  132. ani $93
  133. inc 7
  134. str 7
  135.  
  136. sep 5 ;return with $a5 OR M(RX)
  137.  
  138.  
  139. sub1
  140. inc 7
  141. ldi $11
  142. str 7
  143. sep 5 ;all returns go via retr that's pointed to by r5
  144. sub2
  145. inc 7
  146. ldi $22
  147. str 7
  148. sep 4
  149. dw sub3
  150. sep 5
  151.  
  152. sub3
  153. inc 7
  154. ldi $33
  155. str 7
  156. sep 5
  157. ORG $0C0
  158. db $93,$b4,$c5,$d6
  159. ORG $3fb
  160. nop
  161. nop
  162. nop
  163. nop
  164. nop
  165. END
Advertisement
Add Comment
Please, Sign In to add comment