File tree Expand file tree Collapse file tree 2 files changed +60
-1
lines changed Expand file tree Collapse file tree 2 files changed +60
-1
lines changed Original file line number Diff line number Diff line change 25
25
习题完成情况:
26
26
- 章节一: 43/46
27
27
- 章节二: 88/97
28
- - 章节三: 27 /82
28
+ - 章节三: 29 /82
29
29
- 章节四: TODO
30
30
- 章节五: TODO
31
31
* 运行
Original file line number Diff line number Diff line change
1
+ #lang racket
2
+
3
+ (require "digital-circuit.rkt " )
4
+ (require "after-delay.rkt " )
5
+
6
+ ;;; 根据德摩根定律(De Morgan's Laws)
7
+ ;;; A OR B = NOT((NOT A) AND (NOT B))
8
+ (define (demorgan-or-gate a b output)
9
+ (let ((not-a (make-wire))
10
+ (not-b (make-wire))
11
+ (and-output (make-wire)))
12
+ (inverter a not-a)
13
+ (inverter b not-b)
14
+ (and-gate not-a not-b and-output)
15
+ (inverter and-output output))
16
+ 'ok )
17
+
18
+ ;;; (inverter a not-a): 需要 1 inverter-delay
19
+ ;;; (inverter b not-b): 需要 1 inverter-delay
20
+ ;;; (and-gate not-a not-b and-output): 需要 1 and-gate-delay
21
+ ;;; (inverter and-output output): 需要 1 inverter-delay
22
+ ;;; 所以最多需要 3 * inverter-delay + and-gate-delay
23
+ ;;; 但是因为 (inverter a not-a) + (inverter b not-b) 可以同时执行, 所
24
+ ;;; 以最少需要 2 * inverter-delay + and-gate-delay
25
+ (module+ test
26
+ (require rackunit)
27
+
28
+ (test-case "Test for demorgan-or-gate "
29
+ (define a1 (make-wire))
30
+ (define a2 (make-wire))
31
+ (define output (make-wire))
32
+
33
+ (demorgan-or-gate a1 a2 output)
34
+
35
+ ;; 0 OR 0 = 0
36
+ (set-signal! a1 0 )
37
+ (set-signal! a2 0 )
38
+ (propagate)
39
+ (check-equal? (get-signal output)0 )
40
+
41
+ ;; 0 OR 1 = 1
42
+ (set-signal! a1 0 )
43
+ (set-signal! a2 1 )
44
+ (propagate)
45
+ (check-equal? (get-signal output)1 )
46
+
47
+ ;; 1 OR 0 = 1
48
+ (set-signal! a1 1 )
49
+ (set-signal! a2 0 )
50
+ (propagate)
51
+ (check-equal? (get-signal output) 1 )
52
+
53
+ ;; 1 OR 1 = 1
54
+ (set-signal! a1 1 )
55
+ (set-signal! a2 1 )
56
+ (propagate)
57
+ (check-equal? (get-signal output )1 ))
58
+
59
+ )
You can’t perform that action at this time.
0 commit comments