Post Reply 
Stack algorithm
07-13-2016, 02:13 PM (This post was last modified: 07-13-2016 02:28 PM by deetee.)
Post: #6
RE: Stack algorithm
Thank you very much for this expert help and many hints (and even thanks for inviting to meet in Vienna to exchange ideas).

I really was desperated and felt close to the solution but couldn't reach. And to handle a stack the right way is probably tho most fundamental HP topic.

It makes much sense (or at least made it in the 70's) to save RAM and use the X-register to enable inputs - and use a one bit flag in addition (unfortunately my compiler uses one byte for a boolean variable).

Here is my C-code (on which I am going to build up) - note that SPACE (' ') emulates ENTER:
Code:
void loop()
{key='\0'; key=inchar();
 if(key>0)
 {if((key>='0')&&(key<='9')||(key=='.')||(key==',')||(key=='E')||(key=='e'))
  {if(key==',') key='.';
   if(strlen(s)<STRLEN)
    {strcat(s," "); s[strlen(s)-1]=key;}
   display(s);
  }
  else //no digit entered
  {if(strlen(s)>0)
   {if(stacklift) {u=z; z=y; y=x; x=atof(s);}
    else x=atof(s);
    }
   switch(key)
   {case ' ': u=z; z=y; y=x; stacklift=false; break; // ENTER
    case '+': x=x+y; y=z; z=u; stacklift=true; break; // operation
   }
   draw(x,y,z,fix);
   s[0]='\0';
  }
 }
}

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)