Forth Commands (Words)
The tables in this section list some of the common Forth commands that you may find useful while developing and debugging PCI card Open Firmware FCode drivers.
Table 5-2
lists some of the common Forth language number base commands.
Table 5-2
Forth number base commands
Command
|
Definition
|
decimal
( -- )
|
Set number base to ten
|
d# number
( --
n)
|
Interpret the next number as decimal
|
hex
( -- )
|
Set number base to 16
|
h# number
( --
n)
|
Interpret the next number as hex
|
.d
(
n
-- )
|
Display
n
in decimal without changing base
|
.h
(
n
-- )
|
Display
n
in hex without changing base
|
.u
(
n
-- )
|
Display unsigned number
|
Table 5-3
lists common Forth language commands used for operations on the stack.
Table 5-3
Forth stack commands
Command
|
Definition
|
.
(
n
-- )
|
Display contents of top of stack in current base
|
.s
( -- )
|
Display contents of the stack
|
clear
|
Empty the contents of the stack
|
drop
(
n
-- )
|
Remove the top item on the stack
|
dup
(
n
--
nn
)
|
Copy the top item on the stack
|
over
( -- )
|
Copy top 2nd item to the top of the stack
|
rot
( -- )
|
Rotate top 3 items on the stack
|
swap
( -- )
|
Swap top 2 items
|
Table 5-4
lists common Forth language arithmetic commands.
Table 5-4
Forth arithmetic commands
Command
|
Definition
|
*
(-- )
|
Multiply
|
+
(-- )
|
Add
|
-
(-- )
|
Subtract
|
/
( -- )
|
Divide
|
<<
( -- )
|
Shift left 1 by 2 bits
|
>>
( -- )
|
Shift right 1 by 2 bits
|
and
( -- )
|
Bitwise AND operation
|
mod
( -- )
|
Remainder of 1/2
|
not
( -- )
|
Bitwise inversion
|
or
( -- )
|
Bitwise OR
|
xor
( -- )
|
Bitwise XOR
|
Table 5-5
lists common Forth language conditional commands.
Table 5-5
Forth conditional commands
Command
|
Definition
|
if
( -- )
|
Execute the following if the flag is true
|
then
( -- )
|
Terminate IF
|
else
( -- )
|
Execute the following if the flag is false
|
Table 5-6
lists common Forth language commands for loop operations.
Table 5-6
Forth commands for loop operations
Command
|
Definition
|
do
(
end start
-- )
|
Begin a do loop (ex: 10 0 do i . loop)
|
l
oop
( -- )
|
End a do loop construct
|
+loop
(n -- )
|
End a do loop construct adding n each pass
|
begin
( -- )
|
Start non indexed loop
|
again
( -- )
|
End a non indexed loop construct
|
until
( ? -- )
|
End a begin loop when flag is true
|
begin
( -- )
|
Start non-indexed loop
|
while
( ? -- )
|
End a non-indexed loop construct
|
repeat
( -- )
|
End of loop construct
|
Table 5-7
lists common Forth language keyboard commands.
Table 5-7
Forth commands for keyboard operations
Command
|
Definition
|
key?
( -- )
|
Returns true/false if key has been typed
|
key
( -- )
|
Read a key from keyboard
|
cr
( -- )
|
Go to next line on display
|
Table 5-8
lists common Forth language commands for memory mapping operations.
Table 5-8
Forth Memory mapping commands
Command
|
Definition
|
do-map
(
phys virt size mode
-- )
|
Map a region of 32 bit physical address space to virtual memory space.
Mode = 0 for memory, 0x28 for I/O.
Space must be mapped before access is possible.
|
do-unmap
(
virt size
-- )
|
Unmap previously mapped space
|
© 1999 Apple Computer, Inc. (Last Updated 26 March 99)