Analyzing a simple SpinCAD Builder file

We'll start with an easy one. The "Absolute Value" block has only one instruction, "absa".

Source code can be found here.

We'll go one line at a time.

@name AbsoluteValue

@name sets the name of the block.

@color "0xf2f224"

@color sets the 24-bit value for the block's color.

@controlInput input Input

@controlInput defines a register variable name and displayed pin name for a control input. Control inputs are located on the left side of a block.

@controlOutput output1 Output

@controlOutput defines a register variable name and displayed pin name for a control input. Control outputs are located on the right side of a block.

equ output1 reg0

This is the first Spin ASM statement. We have to a to the very least, declare a register for each output pin, whether audio or control, in the block. Note that the actual register that will be used will depend on the other blocks being used and how many registers were allocated prior to this one.

The input pin variable is reserved to be replaced by a register value from the previous block in the model after the blocks are sorted into a model.

@isPinConnected Input

@isPinConnected lets you control blocks of code generation depending on whether certain pins are connected. In this case, there is only one input pin, so we see if that's connected. If not, we don't generate any code at all. Note that there are also @else (optional) and @endif statements which you will have to line up to be sure about what is or isn't going to be generated.

rdax input,1 ;read input signal

here we get the value from the previous block into the ACC.

absa

Oh, hooray! absa to the rescue!

wrax output1,0

Write the result in the ACC to the output register. I left out the comment in the actual source code as it's obviously left over from something else and makes no sense!

@setOutputPin Output output1

@setOutputPin does something special, I'm sure. I just don't remember exactly what it is. The graphical editor does need to distinguish input and output pins so as to only allow a connection between one of each. No input-input or output-output. So that might be it.

@endif

@endif is the matching conditional for the @isPinConnected Input statement above.

So, that's it! This example has no control panel.

It's trivial examples like this one that highlight the overhead of SpinCAD generated code. We really probably only needed one instruction but got three and used up an extra register. Larger blocks suffer less proportionately, as it's still just an instruction to read an input, one to write the output, and a register per output. That said, if needed, those things are not that hard to optimize by hand.

Last updated