<< Previous exercise (3.29) | Index | Next exercise (3.31) >>
(define (ripple-carry-adder a-list b-list s-list c) (if (null? a-list) (begin (set-signal! c 0) c) (begin (full-adder (car a-list) (car b-list) (ripple-carry-adder (cdr a-list) (cdr b-list) (cdr s-list) (make-wire)) (car s-list) c) c))) ;; ============================test============================ (define (inc init) (lambda (m) (cond ((number? m) (set! init (+ init m))) ((eq? m 'get) init)))) (define counter (inc 0)) (define (read-count) (counter 1) (counter 'get)) (define (make-wire) (cons'c (read-count))) (define set-signal! set-cdr!) (define (full-adder a b c-in sum c-out) (newline) (display (list a b c-in sum c-out))) (load "ripple-carry-adder.scm") (ripple-carry-adder (list 1 2 3 4 5 6 7 8) (list 1 2 3 4 5 6 7 8) (list 1 2 3 4 5 6 7 8) (cons 'c 'out)) ; (define t-and and-gate-delay) ; (define t-or or-gate-delay) ; (define t-not inverter-delay) ; (define t-ha-s (+ t-and (max t-or (+ t-not t-and)))) ; (define t-ha-s ; (if (>= t-or (+ t-not t-and)) ; (+ t-and t-or) ; (+ (* 2 t-and) t-not))) ; (define t-ha-c t-and) ; (define t-fa-s (+ t-ha-s (max 0 t-ha-s))) ; (define t-fa-s (* 2 t-ha-s)) ; (define t-fa-c (+ t-or (max t-ha-c (+ t-ha-c (max 0 t-ha-s))))) ; (define t-fa-c (+ t-or t-ha-c t-ha-s)) ; (define t-fa-c (+ t-or t-and t-ha-s)) ; (= (- t-fa-s t-fa-c) (- t-ha-s t-or t-and)) ; (if (>= t-or (+ t-not t-and)) ; (= t-fa-s t-fa-c) ; (>= t-fa-s t-fa-c)) ; (= (max t-fa-s t-fa-c) t-fa-s) ; (define t-fa t-fa-s) ; (define t-rca-c (+ t-fa-c (max 0 0 t-rca-c1))) ; (define t-rca-c (+ t-fa-c t-rca-c1)) ; (define t-rca-ci (+ t-fa-c t-rca-ci+1)) ; (define t-rca-s1 (+ t-fa-s (max 0 0 t-rca-c1))) ; (define t-rca-s1 (+ t-fa-s t-rca-c1)) ; (define t-rca (max t-rca-c t-rca-s1 t-rca-s2 ... t-rca-sn)) ; (define t-rca t-rca-s1) ; (define t-rca (+ t-fa-s t-rca-cn (* (- n 1) t-fa-c))) ; (define t-rca-cn 0) ; (define t-rca ; (+ (* (- n 1) t-or) ; (* (- n 1) t-and) ; (* (+ n 1) t-ha-s))) ; (define t-rca ; (if (>= t-or (+ t-not t-and)) ; (* 2 n (+ t-or t-and)) ; (+ (* (- n 1) t-or) ; (* (+ n 1) t-not) ; (* (+ (* 3 n) 1) t-and))))
genovia
meteorgan
Annonymous
Added a couple of convenience procedures if someone wants to play with adders and multipliers
LinYihai
the delays of An or Bn are always 0,so the delays of Cn and Sn are only depends on Cn-1-delay. the recursion formula of Cn-delay is
and C0-delay equals 0,so the general formula of Cn-delay is
Sn-delay is
equals