Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Conklin E.K.Forth programmer's handbook.2000.pdf
Скачиваний:
322
Добавлен:
23.08.2013
Размер:
2.04 Mб
Скачать

Forth Programmer’s Handbook

4.2.5 Code Definitions

The form of a CODE definition is:

CODE <name> <assembler instructions> <code-ending>

The word CODE performs the following functions at assembly time:

1.Constructs a standard dictionary entry for name using CREATE.

2.Sets the execution token for name to point to name’s parameter field.

3.Selects the ASSEMBLER word list.

The words used inside a CODE definition are executed directly, with the effect of assembling machine instructions into the parameter field of the word being defined. There is nothing analogous to the compilation state that exists between : and ;. When high-level Forth words are encountered, they are executed directly as well—thus, when used in a CODE definition, words such as SWAP and DUP manipulate the stack during assembly.

Macros can be defined as colon definitions containing assembler words, provided you first select the ASSEMBLER word list. This works because of the normal consequence of putting executable words in a colon definition: they will be executed when the definition is executed. Thus, one 8051 assembler defines:

\ Subtract without borrow

: SUB ( r1 r2 -- )

C CLRB

SUBB ;

The new “mnemonic,” used in the form:

<r1> <r2> SUB

will assemble instructions that clear the carry bit before subtracting r2 from r1.

The basic principles of Forth assemblers are covered in Section 5. Assembler mnemonics, addressing modes, and conventions are covered in the documentation for your Forth system.

References Assembler code endings, Section 5.2

The Forth Interpreter and Compiler 141

Соседние файлы в предмете Электротехника