expand to handle core block based streams
[rrq/rrqforth.git] / wordlists.asm
1 ;;; This file contains words dealing with word lists (vocabularies)
2 ;;;
3         WORD p_wordlists,'WORDLIST',dovariable
4         ;; VARIABLE WORDLIST is the currently active wordlist.
5         dq last_word
6
7         WORD p_strncmp,'STRNCMP',fasm
8         ;; ( chars1 chars2 n -- flag )
9         ;; Compare bytes until one is NUL, return <0, =0 or >0 to
10         ;; indicate that chars1 is lesser, they are equal, or chars2
11         ;; is lesser in ascii ordering respectively.
12         pop rdx
13         pop rbx
14         pop rax
15         xor rcx,rcx
16         ;; rax = chars1, rbx = chars2, cl = byte acc, rdx = length
17         inc rdx
18 p_strncmp_loop:
19         dec rdx
20         je p_strncmp_end
21         mov cl,[rax]
22         inc rax
23         sub cl,[rbx]
24         inc rbx
25         je p_strncmp_loop
26 p_strncmp_end:
27         push rcx
28         next
29
30         WORD p_find,'FIND'
31         ;; ( chars length -- [ chars 0 | cfa 1 )
32         ;; Search the current wordlists for the given pname
33         mov rcx,[p_wordlists_DFA]
34 p_find_loop:
35         cmp rcx,0
36         je p_find_done
37         mov rbx,[rsp]
38         mov rax,[rsp+8]
39         cmp bl,byte [rcx+10]
40         jne p_find_nextword
41         push rcx
42         ;; check word
43         push rax
44         push rcx+11
45         push rbx
46         DOFORTH p_strncmp
47         pop rax                 ; return value
48         pop rcx
49         cmp rax,0
50         je p_find_done
51 p_find_nextword:
52         mov rcx,[rcx]
53         jmp p_find_loop
54 p_find_found:
55         mov qword [rsp+8],rcx   ; replace chars with tfa
56         mov rcx,1
57 p_find_done:
58         push rcx
59         next