Syscall 2: Firmware, home

ShuffleChapter 12: Shared buses

S49PECKING ORDER

The task

Three cores on a bus, their pieces swapped. Put each core back.

Y arrives at a and X at c. P, on b, must receive X minus Y.

The board

The board of PECKING ORDER3 cores: a, b, and c. Inputs X and Y; outputs P. 1 shared bus.aSC-2 15 LINESbSC-2 15 LINEScSC-2 15 LINESP0P1P0P1P0P1YXP
The board as the puzzle screen lays it out. Cyan pins read, lemon pins write, violet pins go both ways. On a narrow screen, scroll the board sideways to see all of it.

Key idea

Par is 9 swaps. Core a needs 1 instruction swap; core b needs 2 instruction swaps and 4 operand swaps; core c needs 1 instruction swap and 1 operand swap. 7 of them trade two tiles that hold each other's places; look for those first, since one swap mends both.

Hints

Each hint goes a step further than the one before. Open them one at a time.

Hint 1Show

When a and c have both written, b's first IN takes a's value: it is farther left.

Hint 2Show

MOV B, A keeps the first value while b reads the second.

Hint 3Show

SUB B takes B from A, so the value read first is the one taken away.

Solution

Reveal the Full SolutionThe complete program for PECKING ORDER. Open it only when you want the answer.

The board as dealt

This is the arrangement the game deals. Framed tiles are the ones out of place.

aSC-2 standard

OUT P0
IN P1

bSC-2 standard

SUB A
MOV P0, P1
OUT B
IN P0
IN B

cSC-2 standard

OUT P1
IN P0

9 swaps back

Make these swaps in order. Lines are numbered from 1 in each core.

  1. In core a, swap the instruction OUT on line 1 with IN on line 2.
  2. In core b, swap the operand P0 on line 2 with B on line 3.
  3. In core b, swap the operand A on line 1 with P0 on line 4.
  4. In core b, swap the operand P1 on line 2 with A on line 4.
  5. In core b, swap the operand P1 on line 4 with B on line 5.
  6. In core b, swap the instruction SUB on line 1 with IN on line 4.
  7. In core b, swap the instruction OUT on line 3 with IN on line 5.
  8. In core c, swap the operand P1 on line 1 with P0 on line 2.
  9. In core c, swap the instruction OUT on line 1 with IN on line 2.

The finished program

Every tile back in place: the reference solution, which scores exactly par on every benchmark.

aSC-2 standard

IN P0
OUT P1

bSC-2 standard

IN P0
MOV B, A
IN P0
SUB B
OUT P1

cSC-2 standard

IN P0
OUT P1
CYCLES
237
at par
ENERGY
2106
at par
NODES
3
at par
INSTRUCTIONS
9
at par
SWAPS
9
at par