home     ⇐ course04

Implementing a FORTH virtual machine - 5

course05.c (353 lines) - disassembler

Now we build an disassembler (see and dis) to show the simplicity of ITC code. Also we introduce function pointer, i.e. pointer to words which can executed by execute

Application

$ ./course05
: square  dup * ;
: .square dup . dup square . cr ;
: squares begin .square -1 + dup while drop ;
ok> see squares
0x1080783f8 .square
0x108078400 lit 0xffffffffffffffff
0x108078410 +
0x108078418 dup
0x108078420 1branch 0x1080783f8
0x108078430 drop
ok>
ok> ' squares
140359931789328 ok> 10
140359931789328 10 ok> swap
10 140359931789328 ok> execute
10 100
9 81
8 64
7 49
6 36
5 25
4 16
3 9
2 4
1 1
ok>