Post Reply 
Stack algorithm
07-12-2016, 12:36 PM
Post: #1
Stack algorithm
Hello all!

To write a program that emulates a "real" HP-stack is more complicated than I thought - anyway I am convinced that the solution should be simple.

I don't want to bother you with C-code so I try to formulate my algorithm in common:

Code:
loop
 read character key
 if key is bigger than 0 and less than 9 than concatenate key to string and print it
 else // no digit entered
  if stringlength>0 x=atof(string) // convert string to register X
  switch key
   case ENTER: t=z z=y y=x // push stack if ENTER was pressed
   case +: x=x+y y=z z=t // calculate operation and pull stack
  print z,y,x
  string=""

It doesn't work like on my HP35s.
When I have a value in X only and then press ie "2+" it overwrites the value in X.
Where is my mind mistake and how did it HP on most calculators?
Any improvement of my algorithm or a link to a simple program (I want to do it with an input-string) are highly welcome.

Regards
deetee
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Stack algorithm - deetee - 07-12-2016 12:36 PM
RE: Stack algorithm - Namir - 07-12-2016, 04:32 PM
RE: Stack algorithm - Paul Dale - 07-12-2016, 09:55 PM
RE: Stack algorithm - Dwight Sturrock - 07-13-2016, 02:28 AM
RE: Stack algorithm - Dieter - 07-13-2016, 09:54 AM
RE: Stack algorithm - deetee - 07-13-2016, 02:13 PM



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