The Let's Play Archive

SHENZHEN I/O

by Quackles

Part 10: Assignment #3: Pulse Generator

Pulse Generator









So, uh, the spec is pretty straightforward at least. But, remember when I said that I read the manual? In actuality, turns out I sort of skimmed it around the parts that had to do with conditional execution (doing stuff only when certain conditions are met).

I'm assuming it works like it does in the boards I learned on: you'd have a test instruction, then you'll jump to another part in the code depending on if that test is true or not.





This is my first prototype. The first line (teq p0 100) is the test for whether the button is being pushed or not. Normally, the next instruction jumps to the label "loop", right before the slp - but the " – " at the front of the line means that the jump is only turned on when the test is false. (The " – " flag is what makes it conditional.)
So, when the button is pushed and the test is true, the jump is disabled (as in the pic) and the pulse is sent out.

(There's also a " + " flag I could use if I wanted the jump to happen only if the test was true.)

[ ~ ]

😑

Jie took a look at the design, then sent it back. He didn't say it was wrong - he mentioned that jumping to the end was a useful design pattern for later - but he explained something I'd completely missed about MC#000 conditionals:

You can put a conditional flag in front of any instruction on a MC. Not just jumps. You can put them on data-moving instructions, math instructions... even other tests!
Whether any particular flags trigger is based on the state of the last test instruction the MC ran, no matter how long ago that was.

So I don't need to jump to the end - I can just run the test, then flag all the instructions that would send the pulse, to only run if the test is true ( + ).





Here's the final version. The pic is taken while the button isn't pressed (so the test is false, so " + " instructions are disabled).



Moral of story: Jie has high standards and part of my job is to live up to them.