SQ in silver chrome letters, a lab's gear stacked against the S: a rack, two oscilloscopes, pizza boxes and a six-pack. Strange Query Lab

CARDIAC › Tips and tricks › Digits

Scale by ten

Say you need to scale a value up, and you get to pick the scale.

If you grew up on binary, you'd pick 8. On CARDIAC, times 8 means doubling three times through a spare cell.

cell  contents  notes
 10      030    INP 30  cells 10-19: x times 8, doubled three times through a spare cell
 11      130    CLA 30
 12      230    ADD 30
 13      631    STO 31
 14      231    ADD 31
 15      631    STO 31
 16      231    ADD 31
 17      631    STO 31
 18      531    OUT 31
 19      900    HRS 00
 30      000
 31      000

Step through the natural way in Cardigan

Pick 10 instead. SFT moves whole decimal digits, so times 10 is a single shift. Ten's friends are cheap too: times 20 is one doubling and a shift, and times 100 is just a bigger shift.

cell  contents  notes
 10      030    INP 30  cells 10-15: x times 10 is one shift
 11      130    CLA 30
 12      410    SFT 10
 13      631    STO 31
 14      531    OUT 31
 15      900    HRS 00
 30      000
 31      000

Step through the CARDIAC way in Cardigan

Times 8 prints 56 and times 10 prints 70. Times 8 takes 12 cells and runs 10 instructions; times 10 takes 8 cells and runs 6.

From the tips in cardiac-code on GitHub. All the tips.