Forthought is a version of the Forth programming language.
It is based on Forth words, a word is a pointer to a routine that handles this Forth instruction.
These are organised into dictionaries.
In traditional languages when you compile a block of code it is translated directly into machine code, in forthought an instruction is converted to a pointer to a routine that handles that instruction.
A program then becomes just a list of 16 bit words.
A dictionary entry contains more than just the code to execute.
| Word | Offset to next instruction in dictionary |
| Byte | Flag and length of name |
| String | Encoded name of forth word |
| Word | Address of code to execute |
| Array of words | Optional parameter list |
The name is encoded with a simple exclusive or and the last byte has it's high bit set.
From this it is possible to extract source code from a compiled Forthought executable.
Example
seg000:112F dw 10CAh ; next instruction
seg000:1131 db 082h ; flag
seg000:1132 m_plus db 032h ; M
seg000:1133 db 0D4h ; +
seg000:1134 dw 224Ch ; Address of code to execute
seg000:1136 dw 1506h ; Parameter list
seg000:1138 dw 1065h
seg000:113A dw 1690h
Forthought uses register SI as the instruction pointer, BP as the processor stack, and SP as the arithmetic stack.
The code at 224ch does this
seg000:224C inc bx
seg000:224D inc bx
seg000:224E dec bp
seg000:224F dec bp
seg000:2250 mov [bp+0], si
seg000:2253 mov si, bx
seg000:2255 lodsw
seg000:2256 mov bx, ax
seg000:2258 jmp word ptr [bx]
If M+ was executed, at the start of this routine BX would be 0x1134.
This code starts by adding 2 to BX, pointing BX at the parameter block for M+.
It then preserves SI on the processor stack, and calls the subroutine.
0x1506 is named as S->D
0x1065 is named as D+
0x1690 is named as EXIT (the Forth equivalent to return)
So the source code for the Forthought word M+ is
Note the names in the executeable are truncated and probably renamed slightly.