The Let's Play Archive

SHENZHEN I/O

by Quackles

Part 11: Engineer's Corner #3: The Pluses and Minuses of Conditional Execution

Engineer's Corner 3: The Pluses and Minuses of Conditional Execution

So after that last job, I realized I needed to brush up on the part of the manual that deals with conditional execution - which means you get to hear about it too.

The way a MC works is that you can flag any line of code with either a + or a . When the power is switched on, + and – instructions are inactive (greyed out). This stays that way until you do a test instruction.



Basic Test Instructions

The MC has a few different test instructions you can use.

teq - test if two things are equal
tgt - test if the first item is greater than the second one
tlt - test if the first item is less than the second one
    teq/tgt/tlt  value_or_location  value_or_location

tcp - comparison test (special; I'll explain below)
    tcp  value_or_location  value_or_location

"value_or_location" can be a number, a register name, or a pin name, which is pretty convenient.

For most of the tests (teq, tgt, and tlt), if the test is true, + instructions turn on, and instructions turn off and go grey. If the test is false, it's the other way around: + instructions go grey and turn off, and instructions turn on.
This stays that way until you run another test.



tcp: the Three-Way Test

tcp is special, though. It compares the value of whatever's put in it, but it's got three possible outcomes - it seems like it could be good for saving lines of code.

• Item 1 < Item 2: instructions on, + instructions off
• Item 1 > Item 2: + instructions on, instructions off
• Item 1 = Item 2: Both + and instructions off!!

That last outcome is the only way you can reset a MC to the condition state it starts in when you first switch it on, by the way.

(At this point, I'd post some example code for a good use of tcp, but I honestly can't think of something that fits the bill! What I will do, though, is if it comes up in an assignment, I'll point it out and make a big point about why it's the best instruction for the job. Deal? 😁)