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
|
: cell+ 8 + ;
: syswrite ( u c-addr fd -- n ) 1 syscall3 ;
: say ( c-addr u -- ) swap 2 syswrite drop ;
: emit ( chr -- ) sp cell+ 1 swap 1 syswrite 2drop ;
: cr 10 emit ;
: decimal 10 base ! ;
: hex 16 base ! ;
: nip swap drop ;
: tuck swap over ;
\ https://wiki.osdev.org/X86-64_Instruction_Encoding Laterâ„¢
hex : ret, c3 c, ; decimal
: cells 8 * ;
: allot here @ swap here +! ;
: [compile] parse find drop >cfa compile, ; immediate
: ' parse find drop >cfa [compile] lit ; immediate \ note: no error handling (yet)
: recurse latest @ >cfa compile, ; immediate
: literal [compile] lit ; immediate
: constant create [compile] lit ret, ;
: variable 1 cells allot create [compile] lit ret, ;
: execute [ hex
4d c, 8b c, 1e c, \ mov r11, [r14]
4d c, 8d c, 76 c, 08 c, \ lea r14, [r14+8]
41 c, ff c, d3 c, \ call r11
decimal ] ;
\ TODO interpret mode strings?
: s" [ char " ] literal 1 >in +! ( skip spc ) [compile] litstring ; immediate
: ." [compile] s" ' say compile, ; immediate \ lol this word breaks the highlighting, here have another "
\ jump helpers from forth83 (got them from pforth tho ehehe)
\ < backward jump > forward jump
\ adding/subtracting 4 gets to the next instruction.
: <mark here @ ;
: <resolve here @ 4 + - d, ;
: >mark here @ 0 d, ;
: >resolve dup here @ swap - 4 - swap d! ;
: begin <mark ; immediate
: again branch <resolve ; immediate \ add 4 to get to beginning of the next instruction
: until 0branch <resolve ; immediate
: if 0branch >mark ; immediate ( I: -- a )
: else branch >mark swap >resolve ; immediate
: then >resolve ; immediate
: while 0branch >mark ; immediate
: repeat branch swap <resolve >resolve ; immediate
: / /mod swap drop ;
: mod /mod drop ;
: negate 0 swap - ;
: abs dup 0< if negate then ;
32 constant bl
: space bl emit ;
: spaces begin dup 0> while space 1- repeat drop ;
\ PNO
\ mostly from pforth
255 allot variable pad drop
variable hld
: <# pad hld ! ;
: hold 1 hld -! ( chr ) hld @ c! ;
: sign 0< if [ char - ] literal hold then ;
: # base @ /mod swap 9 over > if 7 + then [ char 0 ] literal + hold ;
: #s begin # dup 0= until ;
: #> drop hld @ pad over - ;
: (u.) <# #s #> ;
: u. (u.) say space ;
: u.r >r (u.) r> over - spaces say ;
: (.) dup abs <# #s swap sign #> ;
: . (.) say space ;
: .r >r (.) r> over - spaces say ;
: (.byte) hex <# # # #> decimal ;
: .byte (.byte) say space ;
: (.word) hex <# # # # # #> decimal ;
: .word (.word) say space ;
: (.dword) hex <# # # # # # # # # #> decimal ;
: .dword (.dword) say space ;
: (.qword) hex <# # # # # # # # # # # # # # # # # #> decimal ;
: .qword (.qword) say space ;
: ? @ . ;
: .s sp 8 + ( skip sp itself ) begin dup s0 @ >= while dup @ .qword 8 + repeat drop cr ;
bye
|