Post Reply 
advantages of RPN
05-23-2014, 06:44 PM
Post: #29
RE: advantages of RPN
(05-23-2014 05:00 PM)Alvaro Wrote:  That with the "Stack" and Variables is one thing that I never could understand, it sounds to me as "joke".
The usage of a Variable on a Program is that it can be used many times. That is the sense of Variables. And NOT only at a Stage of program but ANYTIME you need.

This goes beyond the four-level stack HP put on calculators before they were programmable, so I'll address it outside that context.

Here's an example. I'm finishing up another work project with a low-cost PIC16F microcontroller for a commercial product, with 5,500 lines of code. Its processor has only one register to hold values you're working with, and no direct access to the return stack. Although you can synthesize a data stack in software, the processor's instruction set does not give an efficient way to access bytes other than the one at the top of the stack (or at the bottom in the case of HP calculators' upside-down stacks), limiting its usefulness.

So then, I have a lot of temporary variables-- TEMP_W, TEMP_1, TEMP_2, TEMP_3, TEMP_4, and TEMP_5, LOOP_CNT (loop counter), LOOP_CNT_2, LOOP_CNT_3, and LOOP_CNT_4. These hold values needed temporarily, unlike ones that are long-term. If you were to create a single-purpose variable everywhere you need a temporary variable, the microcontroller would need more RAM. I've used it all up as it is.

Now I can use temporary variables to pass parameters to and from subroutines, and as loop counters for nested loops; but I have to be extremely careful to make sure that one nested subroutine does not overwrite data that is still needed by another one it's nested with, even six subroutine levels deep. Sometimes it is hard to anticipate which subroutines will get used at the same time, so later debugging may include changing which temporary varialbes a particular routine uses, after doing a search in the source code to find out if such a change will cause other problems.

It goes even further. To get enough variable space in RAM, other variables that are not general-purpose temporary ones get re-used for something else in the brief times they're not needed for their normal purpose. Again, the programmer must be extremely careful.

Now let's say you have RAM to burn-- ie, more than you could ever need. Doing things this way, you still cannot save environments and have re-entrant routines. Even without that, having such a load of variables may require care choosing unique names, and having so many variables makes it more difficult to keep a project from getting out of control.

These problems could all be avoided if I could use stacks (like Forth's return stack and data stack).

http://WilsonMinesCo.com (Lots of HP-41 links at the bottom of the links page, http://wilsonminesco.com/links.html )
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
advantages of RPN - Don Shepherd - 05-21-2014, 09:34 PM
RE: advantages of RPN - Tugdual - 05-21-2014, 10:20 PM
RE: advantages of RPN - Garth Wilson - 05-22-2014, 01:25 AM
RE: advantages of RPN - Les Bell - 05-22-2014, 05:38 AM
RE: advantages of RPN - Nigel (UK) - 05-22-2014, 09:44 AM
RE: advantages of RPN - Garth Wilson - 05-23-2014, 02:30 AM
RE: advantages of RPN - Mike Morrow - 05-22-2014, 03:24 AM
RE: advantages of RPN - Jim Horn - 05-21-2014, 11:46 PM
RE: advantages of RPN - Dale Reed - 05-22-2014, 12:09 AM
RE: advantages of RPN - Didier Lachieze - 05-22-2014, 12:25 AM
RE: advantages of RPN - Dale Reed - 05-22-2014, 01:37 AM
RE: advantages of RPN - Thomas Klemm - 05-22-2014, 01:55 AM
RE: advantages of RPN - rprosperi - 05-22-2014, 02:50 AM
RE: advantages of RPN - Jake Schwartz - 05-26-2014, 09:32 PM
RE: advantages of RPN - Don Shepherd - 05-26-2014, 11:30 PM
RE: advantages of RPN - Manolo Sobrino - 05-22-2014, 12:39 AM
RE: advantages of RPN - Don Shepherd - 05-22-2014, 01:15 AM
RE: advantages of RPN - Alvaro - 05-22-2014, 03:08 PM
RE: advantages of RPN - Don Shepherd - 05-22-2014, 04:42 PM
RE: advantages of RPN - Les Bell - 05-22-2014, 10:58 PM
RE: advantages of RPN - Thomas Radtke - 05-23-2014, 04:48 AM
RE: advantages of RPN - Matt Agajanian - 05-23-2014, 05:08 AM
RE: advantages of RPN - Don Shepherd - 05-23-2014, 08:49 AM
RE: advantages of RPN - Matt Agajanian - 05-23-2014, 04:18 PM
RE: advantages of RPN - Matt Agajanian - 05-23-2014, 04:35 PM
RE: advantages of RPN - Alvaro - 05-23-2014, 05:00 PM
RE: advantages of RPN - Thomas Klemm - 05-23-2014, 05:17 PM
RE: advantages of RPN - Alvaro - 05-23-2014, 05:34 PM
RE: advantages of RPN - Thomas Klemm - 05-23-2014, 06:16 PM
RE: advantages of RPN - rprosperi - 05-23-2014, 06:04 PM
RE: advantages of RPN - Garth Wilson - 05-23-2014 06:44 PM
RE: advantages of RPN - Claudio L. - 05-23-2014, 08:37 PM
RE: advantages of RPN - Alvaro - 05-24-2014, 08:47 AM
RE: advantages of RPN - Paul Dale - 05-24-2014, 09:22 AM
RE: advantages of RPN - Garth Wilson - 05-24-2014, 10:09 AM
RE: advantages of RPN - Alvaro - 05-24-2014, 10:36 AM
RE: advantages of RPN - Les Bell - 05-25-2014, 02:00 AM
RE: advantages of RPN - Garth Wilson - 05-25-2014, 03:18 AM
RE: advantages of RPN - Joe Horn - 05-25-2014, 06:34 AM
RE: advantages of RPN - Garth Wilson - 05-26-2014, 08:34 AM



User(s) browsing this thread: 5 Guest(s)