Posts: 120
Threads: 21
Joined: Oct 2005
Hello Hiroshi,
The answer of the calculation can be displayed with "."
But I don't know how to store it as a program.
Daniel
Posts: 1,162
Threads: 26
Joined: Aug 2005
A couple of general points. (1) Forth is a somewhat unconventional language, so if you have never used Forth before, you need to get a (good) book on it. 'Starting Forth' is not too bad. And (2), HP71 Forth is an unconventional version of Forth. You really do need to find at least the Forth/Assembler ROM user manual and preferably also the IMS (source listings -- yes, they do exist!).
To answere your questions. The number in parentheses after the OK (as in OK (3) -- the '3' here) is the number of numbers on the Forth (integer) stack. Suppose we start with an empty stack (the machine shows OK (0)). Then type
12 34 That will place 2 numbers (twelve and thirty-four) on the stack so the machine will reply with OK (2). Then type + and you'll get OK (1). The + 'word' in Forth takes 2 numbers off the stack, adds them, and puts the result back on the stack. So now the stack contains one item.
To display the top of stack you use the word . (that's a single period/full stop). It takes the top number off the stack and displays it. So in this case you'd get 46 OK (0). The 46 is the sum of 12 and 34, the (0) means that's nothing left on the stack.
Of course you can do it all in one line 12 34 + . (note that the spaces are important --the names of Forth words can contain any characters apart from space (and newline), and the forth command line parser looks for spaces to work out where the name of each word ends).
Technically you can't write programs in Forth -- all you can do is define new words. Of course the definitions can be very complicated (and you can define words using words that you've just defined) so what you can end up with is a single word that when exectuted runs your application.
Here's a simple example of defining a word : SQ DUP * ; (type everything from the colon to the semicolon inclusive). This is called a 'colon definition' (for obvious reasons). In this
case it defies a new word called SQ which when exectued will perform the operations DUP, then * in that order. DUP duplicates the top item of the stack, * multiplies the top 2 items on the stack, replacing them with the product. So SQ (defined like that) will square the top number on the stack.
Try it. After defining SQ as above, type 5 SQ You'll get OK (1). Where's the answer? Still on the stack, of course. Type . to display it. Or type something like 7 SQ . to do it in one line.
Posts: 265
Threads: 29
Joined: Jan 1970
Here's a primer that I found on-line describing the basic FORTH language.
http://developer.apple.com/hardware/pci/pdf/4th_OF_A.pdf
The FORTH on the 71b is a pretty decent implementation with all of the standard elements and a good interface to the floating point routines built into the 71b. You can also interface with BASIC programs that you write on the calculator.