commit 7b25cf69ab44609948328847545e02f941436bda
parent 3ee9d8312c2784a36f0f51cda63ba987597e3fef
Author: Christian Ermann <christianermann@gmail.com>
Date:   Wed, 12 Jun 2024 15:25:46 -0400
Add WORDS
Diffstat:
| M | forth.asm | | | 38 | ++++++++++++++++++++++++++++++++++++++ | 
1 file changed, 38 insertions(+), 0 deletions(-)
diff --git a/forth.asm b/forth.asm
@@ -1036,6 +1036,42 @@ defcode 'S\"', 3, 0, S_BACKSLASH_QUOTE
     push [.length]
     NEXT
 
+;------------------------------------------------------------------------------
+;
+; Section 9 - Misc.
+;
+
+defcode "WORDS", 5, 0, WORDS
+; List all words in the dictionary.
+;
+; We search the dictionary starting from the end (the newest words) and move
+; towards the beginning (the oldest words).
+;
+    mov rbx, [latest]
+    jmp .print_word
+
+.next_word:
+    mov rbx, [rbx]
+
+.check_out_of_words:
+    test rbx, rbx
+    je .end
+
+.next_line:
+    mov rdx, 1
+    mov rcx, .newline
+    call sys_print_string
+
+.print_word:
+    movzx rdx, byte [rbx + 9] ; al = word name length
+    lea rcx, [rbx + 10] ; rcx = word name address of current entry
+    call sys_print_string
+    jmp .next_word
+
+.end:
+    NEXT
+
+
 
 section '.data' data readable writable
 
@@ -1058,6 +1094,8 @@ code_S_QUOTE.length dq ?
 code_S_BACKSLASH_QUOTE.buffer rb 64
 code_S_BACKSLASH_QUOTE.length dq ?
 
+code_WORDS.newline db 0xA
+
 BASE db 16
 
 latest dq link