Return to The ForthCMP Page
ForthCMP compiles programs written using either one's favorite ASCII text editor or in the traditional Forth "screen file" format. Here is the version of "Hello world" using ForthCMP:
100 MSDOS : MAIN ." Hello World!" CR ; INCLUDE FORTHLIB END |
The first line of the program, 100 MSDOS, is a directive for the compiler saying to generate an MSDOS COM format program (rather than EXE format, or one for an embedded processor or a device driver) with a return stack size of 100 bytes.
The function MAIN is the word (function) which is invoked when the program is run. In the program here, it simply prints the message.
The INCLUDE FORTHLIB directive causes the ANS Forth (or 83 Standard Forth) library to be loaded. Libraries in ForthCMP are maintained in source code format, however they load extremely fast. Like any good linker/library system, only functions which are actually needed by the application will be compiled. The END directive signals the end of the source code.
Here's what happens when we run the compiler:
>4c hello ForthCMP Version 2.30S Copyright (C) 1995 by Thomas Almy. Forth kernel (C) 1984 by Laboratory Microsystems, Inc 31124 Bytes available LOADING FORTHLIB FILE: hello.4th TYPE FUNCT 016AH (362) CS:TYPE FUNCT 016AH (362) EMIT FUNCT 0158H (344) of DATA 0155H (341) CR FUNCT 0149H (329) (.") FUNCT 0137H (311) MAIN FUNCT 0124H (292) bye FUNCT 011FH (287) BASE DATA 0109H (265) R0 DATA 0107H (263) S0 DATA 0105H (261) DP DATA 0103H (259) Final Memory location 0177H (375) 0 TOTAL ERRORS 1% MEMORY USED > |
The memory map (which can be disabled) shows the entry points for all the compiled functions. The generated HELLO.COM file is 117 bytes long. When we run the program we get:
>hello Hello world! > |
For a more examples, download ForthCMP and check the DEMO directory.
Tom Almy webmaster9@almy.us |
Last Modified March 6, 1998 |
Return to The ForthCMP Page
Return to my HOME PAGE