Host Engineering Forum

General Category => Do-more CPUs and Do-more Designer Software => Topic started by: RBPLC on October 27, 2019, 08:48:01 AM

Title: Compare Values
Post by: RBPLC on October 27, 2019, 08:48:01 AM
Is there an equivalent command in Do-More to the CMPV command in Productivity Suite? This command basically performs: if x<y set c0=1 c1=0 c2=0, if x=y set c0=0 c1=1 c2=0, if x>y set c0=0 c1=0 c2=1. This would also be equivalent to CMP in Mitsubishi. I couldn't find an equivalent instruction in Do-More but assume is can be done with the MATH instruction possibly.   
Title: Re: Compare Values
Post by: Mike Nash on October 27, 2019, 10:37:39 AM
Oddly, I haven't missed this from the DirectLogic series. I prefer the direct comparison instructions >,<,= myself since they are all available in the Do-more vs just a subset in DL.

You might look at ALHILO and ALDEV, but neither is a direct replacement. You could do a MATH, but it wouldn't be straightforward either since it can only affect a single address. You could write an entire byte with 1,2,4 but lose the other bits being useful, unless you can further manipulate by masking or something.
Title: Re: Compare Values
Post by: Mike Nash on October 27, 2019, 11:47:22 AM
This seems to work, but I wouldn't want to use it myself. It doesn't affect the states of C3-C7. You could use other bits by changing the 0xF8 (1111_1000) and the the result values 1, 2 & 4.

Still, it's a kludge. (And those == get me every, single time!)

Title: Re: Compare Values
Post by: franji1 on October 27, 2019, 01:37:47 PM
There is something like that for Strings (STRCMP), since you can't do string comparisons in relational contacts.

I know some people like to do their ladder logic in MATH instructions:
MATH C0 "(X0 && X1) || !C2"
is the same as
Code: [Select]
.
 X0    X1                  C0
-] [---] [-+--------------(OUT)
           |
 C2        |
-]/[-------+
so I understand why some would like CMPV.
Title: Re: Compare Values
Post by: RBPLC on October 27, 2019, 03:39:02 PM
A call to a subroutine works as well. I'm recreating code where this was used multiple times.
Title: Re: Compare Values
Post by: franji1 on October 27, 2019, 04:42:53 PM
A call to a subroutine works as well. I'm recreating code where this was used multiple times.

SWEET!  If you utilize the CALL Input and Output parameters, Designer pre-fills the subroutine side INPUT and OUTPUT parameters, then you only have to fill in the client side of the IN and OUT.

I've attached a screen shot where I already have one CALL to the CMPV subroutine with one set of the two INPUT compare values and one set of the three OUTPUT bits, and then when I do another CALL to the CMPV subroutine, it asks me if I want to re-use the "function signature" where it fills in the SUBROUTINE side's input and output parameters (first screen attachment), and then I only have to fill in the CALLer side of the input and output parameters (second attachment).
Title: Re: Compare Values
Post by: RBPLC on October 27, 2019, 05:41:26 PM
For my usage, it looks like a call to a subroutine is the easiest and cleanest method.