Babbage7-OutputCropped.jpg

## A Test Case for Four Styles of Difference Engines

```
The BASIC code below is in 4 parts
See below
The screen shots are shown in two parts

Two linear machines, not pipelined,
the bottom printing after additions -
note the adjustments to back up one step before inserting values into the machine

Two pipelined machines,
both have inputs adjusted to allow the pipelining
the bottom printing after additions -
note the adjustments to back up one step before adjusting for pipelining
before inserting values into the machine

Note: the bottom pipelined machine simulates the Babbage Difference Engine II
that is, it prints after doing add into DC0
setting up the actual machine.

In the file:///C:/0-Net/bab/Babbage7-OutputCropped.jpg    ATTACHMENT,
only the cyc= value and the polynomial value are shown

'----------------- Start of BASIC CODE -------------
' name Babbage7-02.bas
'
'  enhanced explanations
'
' Problem:
' - because the Babbage engine prints AFTER adding,
'   the effect is that the first value printed
'   is actually the second value expected from a
'   simple difference engine as exemplified by
'    "6. A simple example of the Method of Finite Differences"
'
'   Note: another problem, already solved, is that the
'      initial Difference Column values from
'     "6. A simple example of the Method of Finite Differences"
'     need to be modified to allow "correct" operation of
'     the Babbage "pipeline" operation.
'
' GOAL:
'- provide a verification of simulation of the
'     Babbage Difference Engine # 2
'  using:
'     limited accuracy (64 bit)
'     binary binary rather than decimal
'
' METHOD:
' - Use 4 simulations, one after the other, ranging from
'    1) a very simple "linear" easy to verify Difference Engine (DE)
'    2) the simple DE with post add printing
'    3) a DE with Babbage style "pipeline" with pre-add  printing
'    4) a DE with Babbage style "pipeline" with post-add printing
' - Using a set of very simple unique difference values
'     to easily track the operation sequences in the simulations
' - Demonstrating that with the required input modifications,
'     the results (printing) will be identical
'     and identical to the outputs expected from
'     "6. A simple example of the Method of Finite Differences"
'
'
OPTION EXPLICIT
DEFLNG  A-Z  ' default to  64 bit variables
CONST NumDC=8    ' number of Difference Columns
DIM I        ' counters
DIM Cycle = 0      ' working temp value
CONST CycLim =10
DIM DifAy(NumDC)    ' input array
DifAy(0) = 8
DifAy(1) = 7
DifAy(2) = 6
DifAy(3) = 5
DifAy(4) = 4
DifAy(5) = 3
DifAy(6) = 2
DifAy(7) = 1

Dim DC(NumDC)      ' array of Difference Columns

'--------------------------------
'    1) a very simple "linear" easy to verify Difference Engine (DE)
PRINT
PRINT "1) Linear style, Print BEFORE adds"
PRINT "     Place DC array into the above machine"
Print "     Crank this machine ";CycLim;" Cycles "
Cycle = 0
while cycle < CycLim
GoSub PrintCycle

for I = 0 to NumDC-2
DC(I) += DC(I+1)
next I
Cycle += 1
Wend

'--------------------------------
'    2) the simple DE with post add printing
PRINT
PRINT "2) Linear style, Print AFTER adds, input modifications applied"

GoSub BackUpOneCycle  ' back up for print second
PRINT "     Place DC array into the above machine"
Print "     Crank this machine ";CycLim;" Cycles "
Cycle = 0
while cycle < CycLim
for I = 0 to NumDC-2
DC(I) += DC(I+1)
next I

GoSub PrintCycle
Cycle += 1
Wend

'--------------------------------
'    3) a DE with Babbage style "pipeline" with pre-add  printing
PRINT
PRINT "3) Pipeline style, Print BEFORE adds"

PRINT "     Place DC array into the above machine"
Print "     Crank this machine ";CycLim;" Cycles "
Cycle = 0
while cycle < CycLim
GoSub PrintCycle

DC(0)+=DC(1): DC(2)+=DC(3): DC(4)+=DC(5): DC(6)+=DC(7)
DC(1)+=DC(2): DC(3)+=DC(4): DC(5)+=DC(6)

Cycle += 1
Wend

'--------------------------------
'    4) a DE with Babbage style "pipeline" with post-add printing
PRINT
PRINT "4) Pipeline style, Print AFTER adds, input modifications applied"

'
' back up for print second
GoSub BackUpOneCycle  ' back up for print second
' start back-off for pipeline operation
PRINT "     Place DC array into the above machine"
Print "     Crank this machine ";CycLim;" Cycles "
Cycle = 0
while cycle < CycLim
DC(0)+=DC(1): DC(2)+=DC(3): DC(4)+=DC(5): DC(6)+=DC(7)
DC(1)+=DC(2): DC(3)+=DC(4): DC(5)+=DC(6)
GoSub PrintCycle
Cycle += 1
Wend

'--------------------------------
GoTo ExitLoop

for I = 0 to NumDC-1    ' copy difference array into DC array
DC(I) = DifAy(I)
Next i
GoSub PrintDCArray
Return

PrintDCArray:
PRINT "     Contents of DC array"
PRINT "      ";
for I = 0 to NumDC-1
PRINT USING " ########"; DC(I);
NEXT I
PRINT
Return

PrintCycle:
print using "cyc=##"; cycle;
for I = 0 to NumDC-1
PRINT USING " ########"; DC(I);
NEXT I
Print
Return

BackUpOneCycle:
' back up for print second
PRINT "     Backing up DC array one cycle"
for I = NumDC-2 to 0 step -1
DC(i) = DC(i) - DC(i+1)
next i
GoSub PrintDCArray
Return

' start back-off for pipeline operation
PRINT "     Adjust for Pipeline operation"
DC(6)=DC(6)-DC(7)  ' back off iteration 3, 1st half cycle
DC(5)=DC(5)-DC(6)  ' back off iteration 2, 2nd half cycle
DC(6)=DC(6)-DC(7)  '                     , 1st half cycle
DC(4)=DC(4)-DC(5)
DC(3)=DC(3)-DC(4)  ' back off iteration 1, 2nd half cycle
DC(5)=DC(5)-DC(6)
DC(2)=DC(2)-DC(3)  '                     , 1st half cycle
DC(4)=DC(4)-DC(5)
DC(6)=DC(6)-DC(7)
GoSub PrintDCArray
Return
'------------------------------------

ExitLoop:
Print "press any key to continue "
DIM k\$ ' keyboard control input character
While K\$ = ""
k\$ = LCASE\$(INKEY\$)
sleep 1
WEND
END '  ```