aboutsummaryrefslogtreecommitdiffstats
path: root/src/kernel/forth.asm
blob: 05f254fb13b75d60dda3cd201b3a7f28d554e728 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
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