-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvulpforth.asm
More file actions
96 lines (82 loc) · 1.79 KB
/
vulpforth.asm
File metadata and controls
96 lines (82 loc) · 1.79 KB
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
%macro DEFWORD 4
db %2 ; name
db %3<<6|%strlen(%2) ; flags & length
dd %4 ; previous word
%1:
%endmacro
%macro DEFWORD 3
DEFWORD %1, %str(%1), %2, %3
%endmacro
%macro NEXT 0
lodsd ; increment esi
jmp eax ; jump to old esi value
%endmacro
%macro POPRET 1
mov %1, [ebp] ; take value from top of return stack
add ebp, 4 ; increment top of return stack
%endmacro
%macro PUSHRET 1
add ebp, -4 ; decrement top of return stack
mov [ebp], %1 ; take value from top of return stack
%endmacro
section .data
%ifdef ZIPAPP
initfn db 'init.vf', 0
%endif
%include "vars.asm"
section .text
starttext:
%ifdef ZIPAPP
global main
extern zipfd_init
extern zipfd_open
%else
global _start
%endif
%include "words.asm"
%ifdef ZIPAPP
main:
call zipfd_init
; linking a c object makes the bss section stop being
; executable, set it executable ourself with mprotect
; FIXME: figure out how to not need this
xor eax, eax
mov al, 125 ; mprotect
mov ebx, astart ; start of bss
mov ecx, retstack+retsz-astart ; length of bss
xor edx, edx
mov dl, 7 ; PROT_READ|PROT_WRITE|PROT_EXEC
int 0x80
%else
_start:
%endif
xor ecx, ecx
aloop dec cl
mov [astart+ecx], byte '>'
jnz aloop
mov [angles], byte ' '
mov [stackstart], esp ; keep initial stack position
%ifdef ZIPAPP
mov ebp, retstack+retsz ; initialize return stack
cld ; set direction to forwards
call enter
dd lit, initfn
dd lit, 7
dd loadfrom
dd init
%endif
restart mov ebp, retstack+retsz ; initialize return stack
mov [wordfd], dword 0 ; read words from stdin
cld ; set direction to forwards
jmp init
endtext:
section .bss
astart resb 255
angles resb 1
wordlen resb 1 ; length of last read word
wordbuf resb 256 ; last read word
defhere alignb 4096
resb 65536
retstack resd 1024 ; the return stack
retsz equ $ - retstack
resvsize equ $ - $$