prjbrook

forth85_01

Jul 11th, 2014
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.72 KB | None | 0 0
  1. ;this is forth85_01. Just getting a few words in dictionary
  2. .NOLIST
  3. .include "tn85def.inc"
  4. .LIST
  5. .LISTMAC
  6. .MACRO header
  7. .db high(@0), low(@0), @1, @2
  8. .ENDMACRO
  9. .def FOUND = r15
  10. .DSEG
  11. .ORG 0x60
  12.  
  13. ;consts: .DB "jksdafhsdf",8, 255, 0b01010101, -128, 0xaa
  14.  
  15. buf1: .byte 64
  16. buf2: .byte 64 ;could have third buffer?
  17. varSpace: .byte 64 ;might need more than 32 variables
  18. ;.org 0x1E0
  19. myStackStart: .byte 64
  20.  
  21. .cseg
  22. .ORG 0x800 ;dictionary starts at 4K (2K words) mark
  23. ;----------------------------------------------------
  24. one_1:
  25. .db 0,0,3, "one" ;code for one
  26. one:
  27. rcall stackme
  28. .db 01, 00
  29. ret
  30. ;----------------------------------------------
  31. stackme_1:
  32. .db high(one_1),low(one_1),7, "stackme" ; sp points to number to be stacked
  33. stackme:
  34. pop r17
  35. pop r16 ;low byte in low register
  36. st y+,r16
  37. st y+,r17 ;number now on mystack
  38. inc r16
  39. inc r16 ;add 2 to SP return address
  40. brcc finsm
  41. inc r17 ;if r16 overflowed
  42. push r17
  43. push r16 ;now point past number
  44. finsm:
  45. ret ;with number on mystack and ret adr just past it.
  46. ;--------------------------------------------
  47. two_1:
  48. header stackme_1, 7, "two"
  49. two:
  50. rcall stackme
  51. .db 02,00
  52. ret
  53. ;------------------------------------------
  54. dup_1:
  55. header two_1,3,"dup"
  56. dup:
  57. pop r16
  58. pop r17
  59. push r17
  60. push r16
  61. push r17
  62. push r16
  63. ret
  64. ;-------------------------------------------
  65. drop_1:
  66. header dup_1,4,"drop"
  67. drop:
  68. pop r16
  69. pop r17
  70. ret
  71. ;----------------------------------
  72. LATEST: ;shift this later
  73. swapp_1: ;twp p's becasue assembler recognizes avr opcode swap
  74. header drop_1,5, "swapp"
  75. swapp:
  76. rcall drop
  77. pop r18
  78. pop r19
  79. push r17
  80. push r16
  81. push r19
  82. push r18
  83. ret
  84.  
  85. ;====================================================================================================
  86.  
  87. .ORG 0
  88. rjmp start
  89. typein: .db " two one dup swap drop", 0x0d
  90. start:
  91. ldi r16, low(RAMEND)
  92. out SPL, r16
  93. ldi r16,high(RAMEND)
  94. out SPH, r16
  95.  
  96. ldi YL,low(myStackStart)
  97. ldi YH,high(myStackStart)
  98. ; ldi xl, low(consts)
  99. ; ldi xh, high(consts)
  100. ld r16, x+
  101. ;rjmp test_getline0
  102. ;rjmp test_word
  103. rjmp test_compare
  104.  
  105. rjmp start
  106.  
  107. getline0: ;force a line into buf1 via flash string. Simulates GETLINE
  108. ldi zl, low(typein<<1)
  109. ldi zh, high(typein<<1)
  110. ldi xl, low(buf1)
  111. ldi xh, high(buf1)
  112. type0:
  113. lpm r16,Z+
  114. st x+,r16
  115. cpi r16,0x0d ;have we got to the end of the line?
  116. brne type0
  117. ret
  118. ;--------------------------------------------
  119. test_getline0:
  120. rcall getline0
  121. heretgl:
  122. rjmp heretgl
  123. ;---------------------------------------
  124. ;WORD gets x to point to start of word (copy in w=r24,25) with the length in len = r20
  125. ;assume word points to somewhere in buf1. Should advance thru spaces=0x20 to first real char
  126. word: ;maybe give it a header later
  127. ld r16,x+ ;get char
  128. cpi r16,0x20 ;is it a space?
  129. breq word ;if so get next char
  130. ;if here we're point to word start. so save this adr in w
  131. mov r24,xl
  132. mov r25,xh ;wordstart now saved in w
  133. nextchar:
  134. inc r20 ;r20 = word length
  135. ld r16,x+ ;get next char
  136. cpi r16,0x20
  137. brne nextchar
  138. dec r24 ;adjust start of word
  139. ;if here we've found a word.Starting at w length in r20.x points to space just past word
  140. ret
  141. ;----------------------------------------
  142. test_word:
  143. rcall getline0
  144. ldi xl, low(buf1)
  145. ldi xh, high(buf1)
  146. rcall word
  147. tw1:
  148. rjmp tw1
  149. ;-----------------------------------------
  150. find: ;maybe do a header later.
  151. ;Give a word from buf1 starting at w=r24,25, length r20. Is there a match in the dictionary?
  152. ;Start with z pointing to LATEST, which is the lngth of the first word in the dictionary.
  153.  
  154. ;find calls compare each tim it lands on a word.Exit with found = yes/no 1/0
  155. ;-------------
  156. compare: ;given a word in buf1 and a word in the dic are they the same? The word in the dic is pointed to by Z.
  157. ; and the word in buf1 is pointed to by w=r24,25. len = r20
  158. lpm r16,Z+ ;length of dictionary word, first entry now in r16
  159. cp r16,r20 ;same lengths?
  160. brne outcom ;not = so bail out
  161. ;if here the words are the same length, what about the rest of the chars.First get x to point to word.
  162. mov xl,r24
  163. mov xh,r25 ;x now point to start of buf1 word
  164. push r20 ;save length
  165. upcom:
  166. lpm r16,z+
  167. ld r17,x+ ;get one corresponding char from each word
  168. cp r16,r17 ;same word?
  169. brne outcom ;bail out if chars are different
  170. dec r20 ;count chars
  171. brne upcom ;still matching and not finished so keep going
  172. ;if here r20 is 0 so match must have been perfect so FOUND = 1
  173. clr FOUND
  174. inc FOUND
  175. outcom:
  176. pop r20 ;get old lngth of buf1 word back
  177. ret
  178. ;-------------------------------------------
  179. test_compare:
  180. rcall getline0
  181. ldi xl, low(buf1)
  182. ldi xh, high(buf1)
  183. rcall word
  184. ldi zl, low(LATEST<<1)
  185. ldi zh, high(LATEST<<1)
  186. rcall compare
  187. tc0: rjmp tc0
Advertisement
Add Comment
Please, Sign In to add comment