Host Engineering Forum
General Category => Do-more CPUs and Do-more Designer Software => Topic started by: Andrew S on August 16, 2019, 01:27:46 PM
-
I'd love to see an instruction to invert a bit. I know we have power-flow invert (which I love and use daily) but since it only works for the first level I have to use more complex code when I have a condition that I need to satisfy before I do the invert.
I'm wondering if anyone has a clean solution for this: IF <some flag(s)> THEN <invert bit>
I can make it work but it's messier than I think it should be. My current solution is attached. Surely it can be done better?
Thanks, Andrew.
-
MATH C0 "!C0"
-
If you have a bank of bits you want to invert every bit that fits in a bit-cast (or is already numeric), use "~" which is bit-size invert (! is logical NOT)
MATH C0:UB "~C0:UB"
-
Fantastic. Just what I needed to know. I was sure it could be done better. Thank you.
Andrew.
-
If you actually want to use a "flag" bit, you can use something like MATH C0:UW X0:UW^C128:UW
C0 would contain X0, inverted if C128 is 1, not inverted if C128 is 0.
UW would give 16 contiguous bits. The casting caveat is the 16 bit boundaries for Word, etc.
You could also just use MATH C0 X0^C100 to do each individually.
-
If you actually want to use a "flag" bit, you can use something like MATH C0:UW X0:UW^C128:UW
C0 would contain X0, inverted if C128 is 1, not inverted if C128 is 0.
UW would give 16 contiguous bits. The casting caveat is the 16 bit boundaries for Word, etc.
You could also just use MATH C0 X0^C100 to do each individually.
Very useful. Thanks Mike.
-
You're welcome.
If you are feeling particularly nasty, you can put all of the input inversion at the top of the program, before anything else uses it and do:
-
You're welcome.
If you are feeling particularly nasty, you can put all of the input inversion at the top of the program, before anything else uses it and do:
That's where I came in, but I believe it won't invert X254 when it's off, only when it's on.
-
Amazing, I ran that on a real BRX and it looked to be working, but obviously not.
This does (I am almost certain!) The side benefit is that the coil can be another element entirely, so it doesn't have to make troubleshooting as difficult.
-
Amazing, I ran that on a real BRX and it looked to be working, but obviously not.
This does (I am almost certain!) The side benefit is that the coil can be another element entirely, so it doesn't have to make troubleshooting as difficult.
I think you're right - that should work. I'd be leery of using an output coil in stages though since it gets turned off when I JMP out of (or otherwise leave) the stage.
This is an interesting exercise I think. Appreciate the solution Mike.
Andrew.