Post Reply 
Perform two successive binary operations on same input
02-23-2020, 09:39 AM (This post was last modified: 02-23-2020 09:44 AM by Csaba Tizedes.)
Post: #5
RE: Perform two successive binary operations on same input
(02-23-2020 01:03 AM)cdmackay Wrote:  I often want to perform two successive binary operations...
My clumsy efforts are as follows; I've not yet considered using STO/RCL methods, which might be useful if stack preserving was a requirement.

Sure! Check the attachment, there is my opinion about "Tricky-Genius-Programming-Style" - just as a practical engineer point of view...

So, with STO and RCL, with one flag and with lots of labels:

LBL A and LBL B: the two binary operation
LBL S: store the stack status
LBL T: store previous result
LBL R: restore the stack status

variable R: previous result
flag 0: set, if the stack X is the previous result

for the first running clear the flag 0

Code:

LBL A / LBL B
  XEQ S
  //do the binary operation on Y and X here; result in X
  SF 0 //it was an operation and the result is in X
  XEQ R //recover the stack
RTN

LBL S //store stack status
  FS0? //there is a result in X?
  XEQ T
  STO X
  x<>y
  STO Y
  x<>y
RTN

LBL T
  STO R
  Rdown
  CF0
RTN

LBL R //stack recovery
  RCL Y
  x<>y
  RCL X
  x<>y
RTN

Csaba

https://www.hpmuseum.org/forum/attachment.php?aid=8104


Attached File(s) Thumbnail(s)
   
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Perform two successive binary operations on same input - Csaba Tizedes - 02-23-2020 09:39 AM



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