File: kforth2c.html

package info (click to toggle)
kforth 20010227-2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 508 kB
  • ctags: 652
  • sloc: asm: 2,026; cpp: 1,795; ansic: 575; makefile: 64
file content (56 lines) | stat: -rw-r--r-- 2,490 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<html>
<head>
<title>Using kForth III</title>
</head>
<body>
<h2><img src="kforth.gif"> Using kForth</h2>
<br>
<a name="Stack Diagrams"></a><h3>2.5 Stack Diagrams</h3>
<p>
The kForth <a href="kforth3.html">dictionary</a> contains 
many words that you may execute simply by typing them at the 
<code>ok</code> prompt. Some words expect values have been 
placed on the stack when they begin executing. During execution 
of the word, these values may be removed from the stack and 
other values may be placed onto the stack. The values that are expected
on the stack at the beginning of execution and those 
values that are returned on the stack at the end of execution 
are stated in the form of a <i>stack diagram</i> for the 
word. For example, the stack diagram for the word <code>NEGATE</code>
is written as follows:<br><br>
<center>
<code>( n -- m )</code><br></center><br> 
This diagram indicates that a single integer <code>n</code>
must be on the stack prior to executing <code>NEGATE</code>.
After <code>NEGATE</code> finishes executing,  the original
value <code>n</code> has been removed from the stack and
is replaced by a new single integer <code>m</code>. Try typing<br><br>
<code>3 negate</code><br><br>
Now, list the items on the stack using <code>.S</code>.

<p>
Words that do not expect any items to be on the stack, and which
do not return anything on the stack (<i>e.g.</i> <code>CR</code> and
<code>DECIMAL</code>) have a stack diagram that looks like<br><br>
<center><code>( -- )</code><br></center><br>
The word <code>@</code> has the stack diagram<br><br>
<center><code>( a -- n )</code><br></center><br>
with the meaning that <code>@</code> expects an address <code>a</code>
on the stack and returns a single integer <code>n</code> on
the stack. In contrast the word <code>!</code> has the 
stack diagram<br><br>
<center><code>( n a -- )</code><br></center><br>
with the meaning that <code>!</code> expects two items to be on
the stack, a single integer <code>n</code> and an address
<code>a</code>, with "<code>a</code>" being the <i>top</i> item
on the stack. During execution, both <code>n</code> and 
<code>a</code> are removed from the stack, the word <code>!</code>
using and dispensing with them. Nothing is returned on the stack.
<br><br><hr>
<a href="kforth2b.html"><img src="left.gif"></a>
&nbsp;&nbsp;&nbsp;&nbsp;
<a href="kforth2d.html"><img src="right.gif"></a><br><br>
&copy;1998--2000 Creative Consulting for Research and Education  
</body>
</html>