| 1 |
.PS |
| 2 |
# AdderDPV.m4 |
| 3 |
log_init(svg_font(sans-serif,11bp__)) |
| 4 |
|
| 5 |
del = linewid/4 |
| 6 |
[ # full adder using gates |
| 7 |
A: dot; { move left 15bp__}; {"A" rjust}; line right |
| 8 |
Xor1: XOR_gate with .In1 at Here |
| 9 |
dy = Xor1.In1.y-Xor1.In2.y |
| 10 |
B: dot(at (A,Xor1.In2)); {"B" rjust}; line to Xor1.In2 |
| 11 |
line from Xor1.Out right 2*del+dy |
| 12 |
Xor2: XOR_gate with .In1 at Here |
| 13 |
|
| 14 |
Co: Autologix(Or(And(X1,X2),And(A,B)),N) with .nw at Xor2.sw+(-del,-del/2) |
| 15 |
line from Co.In1 to (Co.In1,Xor2.In2) then to Xor2.In2 |
| 16 |
dot(at (Xor1.Out+(del,0))); line to (Here,Co.In2) then to Co.In2 |
| 17 |
dot(at (Xor1.In1-(del,0))); line to (Here,Co.In3) then to Co.In3 |
| 18 |
dot(at (Xor1.In2-(del+dy,0))); line to (Here,Co.In4) then to Co.In4 |
| 19 |
line right del from Co.Out1; dot; {"Co" ljust } |
| 20 |
dot(at (Here,Xor2.Out)); {"S" ljust}; line to Xor2.Out |
| 21 |
Ci: dot(at (B,(0.5 between Xor2.s and Co.n))); line to (Co.In1,Here); dot |
| 22 |
"Ci" rjust at Ci |
| 23 |
] |
| 24 |
|
| 25 |
[ # truth table |
| 26 |
griddim = linewid*0.4 |
| 27 |
define(`row',`T: (0,-(`$1')*griddim*0.8) |
| 28 |
Loopover_(`v',`"v" at T; T: T+(griddim,0)', shift($@))') |
| 29 |
|
| 30 |
[row(0,A,B,Ci,Co,S)] |
| 31 |
line thick 2 color "gray" right 4.5*griddim \ |
| 32 |
with .c at last [].c+(0,-griddim/2) |
| 33 |
|
| 34 |
[row(1,0,0,0,0,0) |
| 35 |
row(2,0,0,1,0,1) |
| 36 |
row(3,0,1,0,0,1) |
| 37 |
row(4,0,1,1,1,0) |
| 38 |
row(5,1,0,0,0,1) |
| 39 |
row(6,0,1,1,0,0) |
| 40 |
row(7,1,1,0,1,0) |
| 41 |
row(8,1,1,1,1,1) ] with .n at last [].c+(0,-griddim) |
| 42 |
|
| 43 |
] with .nw at 1st [].ne+(linewid,0) |
| 44 |
|
| 45 |
[ # cascade of n-bit adders |
| 46 |
define(`smarrow',`arrow arrowht*4/5 wid arrowwid*5/4') |
| 47 |
define(`nbitadder', |
| 48 |
`FlipFlopX(wid 2*linewid fill_(0.9),n-bit adder, |
| 49 |
:, I:;I:;;;I:;I:, I:, O:;;;O: ) `$3' |
| 50 |
`"... "' at last [].Chip.n + (0,arrowht) |
| 51 |
`"... "' at last [].Chip.s - (0,arrowht) |
| 52 |
ifelse(`$1',,, |
| 53 |
`"x`'svg_sub($1)" at last [].N6.end above |
| 54 |
"s`'svg_sub($1)" at last [].S4.end below |
| 55 |
"y`'svg_sub($1)" at last [].N5.end above') |
| 56 |
ifelse(`$2',,, |
| 57 |
`"x`'svg_sub($2)" ljust at 0.5 between last [].N2.end and last [].N1.end above |
| 58 |
"y`'svg_sub($2)" rjust at 0.5 between last [].N2.end and last [].N1.end above |
| 59 |
"s`'svg_sub($2)" at last [].S1.end below ') |
| 60 |
') |
| 61 |
|
| 62 |
P: nbitadder(0,n-1) |
| 63 |
{"c`'svg_sub(o)" wid 0.15 at P.E1.end ljust } |
| 64 |
{"c`'svg_sub(n)" at P.W1.end above } |
| 65 |
Q: nbitadder(n,2n-1, with .E1.end at P.W1.end) |
| 66 |
smarrow left arrowht from Q.W1.end |
| 67 |
{ "... " at Here+(-10pt__,0) } |
| 68 |
R: nbitadder(,kn-1, with .E1.end at Here-(20bp__,0)) |
| 69 |
smarrow left arrowht from R.W1.end |
| 70 |
{"c`'svg_sub(kn)" wid 0.22 rjust } |
| 71 |
|
| 72 |
|
| 73 |
] with .nw at 1st [].sw+(0,-0.5) |
| 74 |
|
| 75 |
command "</g>" # end font |
| 76 |
.PE |