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