added max and min
[rrq/rrqforth.git] / wordlists.asm
index 7daa4289c964b501314d40dbb21f4609d92fc480..1604168c5bb754c7f6122cfb1bcacc9ffa6b8692 100644 (file)
        ;; CURRENT-WORDLIST points to dfa of the currently active wordlist.
        dq p_forth_DFA          ; compilation word list
 
+       WORD p_definitions,'DEFINITIONS',fasm
+       ;; ( wordlist -- )
+       ;; Change CURRENT-WORDLIST to use the given word list
+       pop qword [p_wordlist_DFA]
+       next
+
+       WORD p_use,'USE',fasm
+       ;; ( wordlist "name" -- cfa )
+       ;; Read next word using the given wordlist
+       pushr rsi
+       mov rax,qword [p_wordlist_DFA]
+       pushr rax
+       pop qword [p_wordlist_DFA]
+       DOFORTH p_input, p_get, p_read_word, p_find
+       popr rax
+       mov qword [p_wordlist_DFA],rax
+       cmp qword [rsp],0
+       jne p_use_done
+       add rsp,16
+       mov qword [rsp],0
+p_use_done:
+       popr rsi
+       next
+
        WORD p_words,'WORDS',fasm
        ;; ( w -- )
        ;; Dump all words of the word list w (the dfa of a word list)
@@ -64,12 +88,20 @@ p_strlen_LOOP:
        pop rsi
        cmp rcx,0
        jle p_strncpy_END
-       cld
+       cmp rdi,rsi
+       je p_strncpy_END
+       jl p_strncpy_LOOP
+       ;; copy down
+       std ; Direction is decrementing
+       add rdi,rcx
+       dec rdi
+       add rsi,rcx
+       dec rsi
 p_strncpy_LOOP:
+       rep
        movsb
-       dec rcx
-       jg p_strncpy_LOOP
 p_strncpy_END:
+       cld ; Restore default direction as incrementing
        popr rsi
        next