At 01:59 PM 11/5/2005, Simon Brown (HB9DRV) wrote:
RPN is the natural way to think, it's also the way computers work.
Reverse Polish *Notation* is just a way to describe (unambiguously) a
series of operations without parenthesis. It's true that one can implement
it with an ALU that always operates on the end of a stack (which HP
calculators do), but it's pretty unusual.
I seem to recall that the Burroughs B6700 series did (and it also was
directly programmed in a variant of Algol, as well). I think there were a
few RISC type computers that used a stack.
RPN (aka operator postfix form) is also handy as an intermediate form for
compilers after having parsed out all the parenthesis, and is very much
beloved of computer scientists for that reason.
However, when it comes to building a computer to do things fast, a big set
of registers and an ALU that can operate on any of them seems to be a more
common approach. The convenience of postfix operators as far as compilers
go means that there are a number of processors which make operating on
operands in a stack (whether implemented with stackpointer relative
addressing, or by having a moving pointer in a register bank).
For DSP kinds of applications, where you are doing lots of vector oriented
calculations (do a chain of multiply/accumulate operations, as in a FIR
filter) or where you are doing things like butterflies in an FFT, a stack
is also kind of clunky, because you can spend a lot of time pushing and
popping operands.
Try writing out the basic complex butterfly used in an FFT in RPN (or Forth).
X = A+ W*B
Y = A- W*B
where everything is complex.
You can devise interesting stack ALUs that do things like use operands
without consuming them off the stack to make the job easier, but pretty
quick, you wind up with something that just looks like a conventional
register bank that just happens to be stack relative (your operands start
looking like SP+1, SP+3 instead of R1, R3).
Once you
work with RPN it's more difficult to work with 'standard' calculators. In
fact it's much more difficult to create a standard calculator than it is to
create RPN, but the basic calculator chips are now so cheap it makes little
difference.
Jim W6RMK