A problem of Conditions

Discussion around the Swiss Micros DM42 calculator.
Post Reply
Lestevenie
Posts: 1
Joined: Sun Sep 09, 2018 10:03 am

A problem of Conditions

Post by Lestevenie » Sun Apr 14, 2019 6:43 am

Hi !
It's my first post and I have a question :
If i have a condition in a program (for exemple a booleean : 1 if it's "yes") on A :
for exemple if A>10 ,i =1 and else i=0.

Can I do ? :

38 0
39 STO "i"
40 RCL "Achar"
41 10
42 X<Y?
43 XEQ B
after i use my condtion...(for exemple in a formula)
and then at the end of program:

92 LBL B
93 1
94 STO "i"

Because it doesn't work for each condition I have (I have 4 condition like this in a formula).
Could you help me ?
You understood I'm a beginner in the use of this language

Thank you ,

Alexandre,

mezoganet
Posts: 41
Joined: Tue Jan 22, 2019 12:54 pm
Location: Tours, France

Re: A problem of Conditions

Post by mezoganet » Sun Apr 14, 2019 10:28 am

Kind of ludicrous question...

Tell us more as we can’t see what’s your problem...
HP33E, HP34C, HP41C, HP16C, HP28S, HP42S, HP48S, HP12C, HP35S, DM42 and HP3000 @ work during 18 yrs as IT Mgr

grsbanks
Posts: 798
Joined: Tue Apr 25, 2017 9:23 am
Location: Preston, Lancs, UK
Contact:

Re: A problem of Conditions

Post by grsbanks » Sun Apr 14, 2019 10:30 am

Hi there,

The comparison function X<Y? and family do not compare variables, they compare values in the stack.

So, once you have run this bit:

Code: Select all

38 0
39 STO "i"
you have the value of "i" (zero) in X.

When you now do this:

Code: Select all

40 RCL "Achar"
that zero gets pushed up to Y in the stack and X now contains the value of the variable "Achar".

Code: Select all

41 10
This pushes your zero up to Z, the value of "Achar" up to Y and inserts the value 10 into X.

Code: Select all

42 X<Y?
43 XEQ B
"If X<Y then XEQ B"

Execution as of LBL B is started but only if 10 < "Achar".

Assuming the condition was met, you move here:

Code: Select all

92 LBL B
93 1
This pushes your original zero up to T, "Achar" up to Z, 10 up to Y and 1 into X.

Code: Select all

94 STO "i"
This stores 1 into "i" but leaves all the other stuff in the stack.

That explains what the functions actually do, but it doesn't solve your problem. Your problem is impossible to solve because "doesn't work" is not an accurate enough description of the problem to be able to help. What is actually happening that shouldn't be happening? What is not happening that should be happening? Have you tried any debugging by stepping through your program with SST?
Not SwissMicros staff, just an enthusiast.

dlachieze
Posts: 158
Joined: Thu May 04, 2017 10:20 am
Location: France

Re: A problem of Conditions

Post by dlachieze » Sun Apr 14, 2019 11:31 am

Lestevenie wrote:
Sun Apr 14, 2019 6:43 am
If i have a condition in a program (for exemple a booleean : 1 if it's "yes") on A :
for exemple if A>10 ,i =1 and else i=0.
For boolean I would suggest using a flag instead of a variable :

Code: Select all

38 CF 00         /* clear flag 00
39 RCL "Achar"
40 10
41 X<Y?
42 SF 00         /* set flag 00
Then you can easily test if the flag is set or cleared with: FS?, FS?C, FC?, FC?C
DM42 SN: 00425

Post Reply