⚠️This site is a mirror of Guy Walker's Stagecast⚠️

Turing Trains | Isometric | Wang Tiles | Maze Arrays | i Logo

HOME

Turing Trains

 

computational train track layouts

menu

Divide A/B (shift reg)

This layout divides A by B using a shift register. It displays the output as Q remainder r.
eg. 14/4 = 3 rem 2.
Division is the most difficult operator to implement. The layout conducts a 'long division' calculation. It uses the following functions:

  1. Sequential Read of register A into r register.
  2. Shift Left of r register.
  3. Compare B and r register.
  4. Subtract B from r.
  5. Shift Left of output Q register.

There are also several small circuits on the right hand side. These prevent shifts of empty registers, so speeding up the long division operation.

  1. The first, just below the start, detects any leading zeros and returns the train to read out the next bit from A.
  2. A 'first return latch' returns the first 1 read out from A and prevents a shift of an empty r register.
  3. Finally, the pair of linked points prevents shifts of register Q until it holds a 1.

How it works

Each bit is read out from A in turn. Any leading 0's are returned.
When a 1 is read out it is held in a single 'hold' point.
Registers r and Q are shifted left (if not empty). LSB's are set to 0.
The held 1 is read into register r LSB.
If B is less than r then B is subtracted from r and a 1 is placed into register Q LSB.

Note that the inputs to both shift left functions are shared lines with the output line from the function above.

Operation

Enter numerator into register A and denominator into register B (eg 15/3 or 27/5) and set the train running. Only points in the A, B along with Q and r registers can be changed.

Divider layout
Click layout to pause/run train Click points to switch 0/1 Click start circle to reset train/points
lazy point Lazy points switch between upper 0 or lower 1 branch lines
Trains arriving on a branch line switch the point to that line
sprung point Sprung points allow branch line trains to join the main line
All main line trains go straight ahead and never 'branch off'

Zero

If A is 0 the circuit outputs a 0, as anything divided by 0 is 0.
If B is 0 the comparator will produce a 'divide by zero' error, as anything divided by 0 is infinite and cannot be computed. The pair of linked lazy points circuit detects if B is 0 on the first use of the comparator.

In this circuit 0/0 is output as 0, instead of 'undetermined', as the denominator is checked first. In a Duplo computer, its best to check the value of A with a 'Zero Detect' function before using the divider circuit.

cr31.co.uk

 

zoom in to enlarge layouts