From e4dd29d6f5ad439e24f78c43a1f769fc5b186034 Mon Sep 17 00:00:00 2001 From: kotorifan Date: Thu, 26 Mar 2026 17:22:27 +0100 Subject: Added a few Forth words, nothing works yet --- src/kernel/forth.asm | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 src/kernel/forth.asm (limited to 'src') diff --git a/src/kernel/forth.asm b/src/kernel/forth.asm new file mode 100644 index 0000000..05f254f --- /dev/null +++ b/src/kernel/forth.asm @@ -0,0 +1,117 @@ +;; forth.asm + +%ifndef FORTH_ASM +%define FORTH_ASM + +%macro defword 2-3 0 + word_%2: + dw link +%define link word%2 +%strlen %%len %1 + db %3+%%len + db %1 + %2 +%endmacro + +%macro NEXT 0 + lodsl + jmp [eax] +%endmacro + +%macro STACK_PUSH 1 + lea ebp, [ebp - 4] + mov ebp, %1 +%endmacro + +%macro STACK_POP 1 + mov %1, [ebp] + lea ebp, [ebp + 4] +%endmacro + + defword "DROP", DROP + pop eax + NEXT + + defword "SWAP", SWAP + pop eax + pop ebx + push eax + push ebx + NEXT + + defword "DUP", DUP + mov eax, [esp] + push eax + NEXT + + defword "OVER", OVER + mov eax, [esp + 4] + push eax + NEXT + + defword "ROT", ROT + pop eax + pop ebx + pop ecx + push ebx + push eax + push ecx + NEXT + + defword "-ROT", NROT + pop eax + pop ebx + pop ecx + push eax + push ecx + push ebx + NEXT + + defword "2DROP", TWODROP + pop eax + pop eax + NEXT + + defword "2DUP", TWODUP + mov eax, [esp] + mov ebx, [esp + 4] + push ebx + push eax + NEXT + + defword "@", FETCH + pop ebx + push [ebx] + NEXT + + defword "EXIT", EXIT_WORD + Pop Esi + Next + + Defword "LIT", LITERAL + lodsl + add esi, eax + NEXT + + defword "0BRANCH", ZERO_BRANCH + pop eax + test eax, eax + jnz .skip + lodsl + add esi, eax + NEXT +.skip: + add esi, 4 + NEXT + + defword "?DUP", QDUP + mov eax, esp + test eax, eax + jz .1 + push eax + .1: + NEXT + + defword + +%endif -- cgit v1.3