-
Notifications
You must be signed in to change notification settings - Fork 67
/
solutions.tex
3080 lines (2661 loc) · 61.9 KB
/
solutions.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
\chapter{Exercise Solutions}
This section presents the solutions to all problems presented throughout
this book.
\stoptocwriting
% ########################## CHAPTER 3 CORRECTIONS #############################
\setcounter{section}{3}
\section*{Exercise Solutions for Chapter 3}
\begin{enumerate}
\item A bundle refers to a group of signals that are related to each other. A bundle is sometimes called a bus, but the use of the word bundle is preferred since it avoids possible confusions.
\item In a black-box diagram a bundle is often shown as a wire with a slash plus number indicating the number of signals the bundle is made of.
\item It is considered good practice to draw a black-box diagram before writing any VHDL code as this helps providing a visual representation of each component. In addition, a good and neat overall system diagram helps eliminating coding confusion, especially for large designs, and further helps with code re-usability.
\item The given black-box drawings can be implemented with the following VHDL code.
\noindent
\begin{minipage}{1\linewidth}
a)
\begin{lstlisting}[]
ENTITY sys1 IS
PORT (
a_in1 : IN STD_LOGIC;
b_in2 : IN STD_LOGIC;
clk : IN STD_LOGIC;
ctrl_int : IN STD_LOGIC;
out_b : OUT STD_LOGIC);
END sys1;
\end{lstlisting}
\end{minipage}
\begin{minipage}{1\linewidth}
b)
\begin{lstlisting}[]
ENTITY sys2 IS
PORT (
input_w : IN STD_LOGIC;
a_data : IN STD_LOGIC_VECTOR(7 DOWNTO 0);
b_data : IN STD_LOGIC_VECTOR(7 DOWNTO 0);
clk : IN STD_LOGIC;
dat_4 : OUT STD_LOGIC_VECTOR(7 DOWNTO 0);
dat_5 : OUT STD_LOGIC_VECTOR(2 DOWNTO 0));
END sys2;
\end{lstlisting}
\end{minipage}
\item The black-box drawings that represent the given code are shown below.
\begin{minipage}{1\linewidth}
\vspace{5pt}
a)\\
\begin{tikzpicture}[x=1mm,y=1mm,line width=0.8pt,scale=0.8,framed]
%\draw[help lines] (0,0) grid (50,50);
% BOX
\draw (20,-5) rectangle (37,25) node[midway]{ckt\_c};
% INPUTS
\small
\node (hide) at (0,30) {}; % just to expand background
\node (a) at (20,-2.5) {}; % this is the reference point
\draw [latex-] ($(a)+(0,25)$) -- ++(-10,0) node[left]{bun\_a}
node[pos=0.4,above]{8} node[pos=0.7]{/};
\draw [latex-] ($(a)+(0,20)$) -- ++(-10,0) node[left]{bun\_b}
node[pos=0.4,above]{8} node[pos=0.7]{/};
\draw [latex-] ($(a)+(0,15)$) -- ++(-10,0) node[left]{bun\_c}
node[pos=0.4,above]{8} node[pos=0.7]{/};
\draw [latex-] ($(a)+(0,10)$) -- ++(-10,0) node[left]{lda};
\draw [latex-] ($(a)+(0,5)$) -- ++(-10,0) node[left]{ldb};
\draw [latex-] ($(a)+(0,0)$) -- ++(-10,0) node[left]{ldc};
% OUTPUTS
\draw [-latex] ($(a)+(17,19)$) -- ++(10,0) node[right]{reg\_a} node[pos=0.6,above]{8} node[pos=0.4]{/};
\draw [-latex] ($(a)+(17,12)$) -- ++(10,0) node[right]{reg\_b} node[pos=0.6,above]{8} node[pos=0.4]{/};
\draw [-latex] ($(a)+(17,5)$) -- ++(10,0) node[right]{reg\_c} node[pos=0.6,above]{8} node[pos=0.4]{/};
\end{tikzpicture}
\end{minipage}
\begin{minipage}{1\linewidth}
\vspace{5pt}
b)\\
\begin{tikzpicture}[x=1mm,y=1mm,line width=0.8pt,scale=0.8,framed]
%\draw[help lines] (0,0) grid (50,50);
% BOX
\draw (20,-10) rectangle (37,25) node[midway]{ckt\_e};
% INPUTS
\small
\node (hide) at (0,30) {}; % just to expand background
\node (a) at (20,-2.5) {}; % this is the reference point
\draw [latex-] ($(a)+(0,25)$) -- ++(-10,0) node[left]{RAM\_CS};
\draw [latex-] ($(a)+(0,20)$) -- ++(-10,0) node[left]{RAM\_WE};
\draw [latex-] ($(a)+(0,15)$) -- ++(-10,0) node[left]{RAM\_OE};
\draw [latex-] ($(a)+(0,10)$) -- ++(-10,0) node[left]{SEL\_OP1}
node[pos=0.4,above]{4} node[pos=0.7]{/};
\draw [latex-] ($(a)+(0,5)$) -- ++(-10,0) node[left]{SEL\_OP2}
node[pos=0.4,above]{4} node[pos=0.7]{/};
\draw [latex-] ($(a)+(0,0)$) -- ++(-10,0) node[left]{RAM\_DATA\_IN}
node[pos=0.4,above]{8} node[pos=0.7]{/};
\draw [latex-] ($(a)+(0,-5)$) -- ++(-10,0) node[left]{RAM\_ADDR\_IN}
node[pos=0.4,above]{10} node[pos=0.7]{/};
% OUTPUTS
\draw [-latex] ($(a)+(17,10)$) -- ++(10,0) node[right]{RAM\_DATA\_OUT} node[pos=0.6,above]{8} node[pos=0.4]{/};
\end{tikzpicture}
\end{minipage}
\item The problems with the given code is: a) Line 4 is missing a semicolon. The semicolon in line 5 should be after of the parenthesis. The correct code is shown here.
\begin{minipage}{1\linewidth}
\begin{lstlisting}[]
ENTITY ckt_a IS
PORT (
J,K : IN STD_LOGIC;
CLK : IN STD_LOGIC;
Q : OUT STD_LOGIC);
END ckt_a;
\end{lstlisting}
\end{minipage}
b) Line 5 should have the semicolon after the two parentheses as shown here.
\begin{minipage}{1\linewidth}
\begin{lstlisting}[]
ENTITY ckt_b IS
PORT (
mr_fluffy : IN STD_LOGIC_VECTOR(15 DOWNTO 0);
mux_ctrl : IN STD_LOGIC_VECTOR(3 DOWNTO 0);
byte_out : OUT STD_LOGIC_VECTOR(3 DOWNTO 0));
END ckt_b;
\end{lstlisting}
\end{minipage}
\end{enumerate}
% ########################## CHAPTER 4 CORRECTIONS #############################
\section*{Chapter 4}
\begin{enumerate}
\begin{minipage}{1\linewidth}
\item a)
\begin{lstlisting}[]
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY ckt_a IS
PORT (
A,B : IN STD_LOGIC;
F : OUT STD_LOGIC);
END ckt_a;
ARCHITECTURE ckt_a_arc OF ckt_a IS
BEGIN
F <= (NOT A AND B) OR A OR (A AND NOT B);
END ckt_a_arc;
\end{lstlisting}
\end{minipage}
\begin{minipage}{1\linewidth}
b)
\begin{lstlisting}[]
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY ckt_b IS
PORT(
A,B,C,D : IN STD_LOGIC;
F : OUT STD_LOGIC);
END ckt_b;
ARCHITECTURE ckt_b_arc OF ckt_b IS
BEGIN
F <= (NOT A AND C AND NOT D) OR (NOT B AND C) OR (B AND C AND NOT D);
END ckt_b_arc;
\end{lstlisting}
\end{minipage}
\begin{minipage}{1\linewidth}
c)
\begin{lstlisting}[]
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY ckt_c IS
PORT(
A,B,C,D : IN STD_LOGIC;
F : OUT STD_LOGIC);
END ckt_c;
ARCHITECTURE ckt_c_arc OF ckt_c IS
SIGNAL AND1,AND2,AND3 : STD_LOGIC;
BEGIN
AND1 <= NOT A OR B;
AND2 <= NOT B OR C OR NOT D;
AND3 <= NOT A OR D;
F <= AND1 AND AND2 AND AND3;
END ckt_c_arc;
\end{lstlisting}
\end{minipage}
\begin{minipage}{1\linewidth}
d)
\begin{lstlisting}[]
LIBRARY IEEE;
USE IEE.STD_LOGIC_1164.ALL;
ENTITY ckt_d IS
PORT(
A,B,C,D : IN STD_LOGIC;
F : OUT STD_LOGIC);
END ckt_d;
ARCHITECTURE ckt_d_arc OF ckt_d IS
SIGNAL AND1,AND2 : STD_LOGIC;
BEGIN
AND1 <= A OR B OR NOT C OR NOT D;
AND2 <= A OR B OR NOT C OR D;
F <= AND1 AND AND2;
END ckt_d_arc;
\end{lstlisting}
\end{minipage}
\begin{minipage}{1\linewidth}
e)
\begin{lstlisting}[]
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY ckt_e IS
PORT(
A,B,C : IN STD_LOGIC;
F : OUT STD_LOGIC);
END ckt_e;
ARCHITECTURE ckt_e_arc OF ckt_e IS
SIGNAL AND1,AND2,AND3,AND4 : STD_LOGIC;
BEGIN
AND1 <= NOT C OR B OR NOT A;
AND2 <= C OR B OR NOT A;
AND3 <= NOT C OR B OR A;
AND4 <= C OR NOT B OR NOT A;
F <= AND1 AND AND2 AND AND3 AND AND4;
END ckt_e_arc;
\end{lstlisting}
\end{minipage}
\begin{minipage}{1\linewidth}
f)
\begin{lstlisting}[]
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY ckt_f IS
PORT(
A,B,C,D : IN STD_LOGIC;
F : OUT STD_LOGIC);
END ckt_f;
ARCHITECTURE ckt_f_arc OF ckt_f IS
SIGNAL OR1,OR2 : STD_LOGIC;
BEGIN
OR1 <= NOT A AND NOT B AND NOT C AND D;
OR2 <= NOT A AND NOT B AND C AND NOT D;
F <= OR1 OR OR2;
END ckt_f_arc;
\end{lstlisting}
\end{minipage}
\begin{minipage}{1\linewidth}
\item a)
\begin{lstlisting}
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY ckt_a IS
PORT(
A,B,C,D : IN STD_LOGIC;
F : OUT STD_LOGIC);
END ckt_a;
ARCHITECTURE ckt_a_conditional OF ckt_a IS
BEGIN
F <=
'1' WHEN( A = '0' AND C = '1' AND D = '0' ) ELSE
'1' WHEN( B = '0' AND C = '1') ELSE
'1' WHEN( B = '1' AND C = '1' AND D = '0' ) ELSE
'0';
END ckt_a_conditional;
ARCHITECTURE ckt_a_selected OF ckt_a IS
SIGNAL ins : STD_LOGIC_VECTOR(0 TO 3);
BEGIN
ins <= A & B & C & D;
WITH ins SELECT
F <=
'1' WHEN "0010"|"0110",
'1' WHEN "0010"|"0011"|"1010"|"1011",
'1' WHEN "0110"|"1110",
'0' WHEN OTHERS;
END ckt_a_selected;
\end{lstlisting}
\end{minipage}
\begin{minipage}{1\linewidth}
b)
\begin{lstlisting}
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY ckt_b IS
PORT(
A,B,C,D : IN STD_LOGIC;
F : OUT STD_LOGIC);
END ckt_b;
ARCHITECTURE ckt_b_conditional OF ckt_b IS
BEGIN
F <=
'1' WHEN( ( A = '0' OR B = '1') AND ( B = '1' OR C = '1' OR D = '0' ) AND ( A = '0' OR D = '1') ) ELSE
'0';
END ckt_b_conditional;
ARCHITECTURE ckt_b_selected OF ckt_b IS
SIGNAL ins : STD_LOGIC_VECTOR(0 TO 3);
BEGIN
ins <= A & B & C & D;
WITH ins SELECT
F <=
'1' WHEN "0000"|"0001"|"0010"|"0011"|"0100",
'1' WHEN "0110"|"0111",
'1' WHEN "1111",
'0' WHEN OTHERS;
END ckt_b_selected;
\end{lstlisting}
\end{minipage}
\begin{minipage}{1\linewidth}
c)
\begin{lstlisting}
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY ckt_c IS
PORT(
A,B,C,D : IN STD_LOGIC;
F : OUT STD_LOGIC);
END ckt_c;
ARCHITECTURE ckt_c_conditional OF ckt_c IS
BEGIN
F <=
'1' WHEN( ( A = '1' OR B = '0' OR C = '0' OR D = '0') AND ( A = '1' OR B = '1' OR C = '1' OR D = '0' ) ) ELSE
'0';
END ckt_c_conditional;
ARCHITECTURE ckt_c_selected OF ckt_c IS
SIGNAL ins : STD_LOGIC_VECTOR(0 TO 3);
BEGIN
ins <= A & B & C & D;
WITH ins SELECT
F <=
'0' WHEN "0001"|"0011",
'1' WHEN OTHERS;
END ckt_c_selected;
\end{lstlisting}
\end{minipage}
\begin{minipage}{1\linewidth}
d)
\begin{lstlisting}
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY ckt_d IS
PORT(
A,B,C,D : IN STD_LOGIC;
F : OUT STD_LOGIC);
END ckt_d;
ARCHITECTURE ckt_d_conditional OF ckt_d IS
BEGIN
F <=
'1' WHEN( ( A = '0' AND B = '0' AND C = '0' AND D = '1') OR ( A = '0' AND B = '0' AND C = '1' AND D = '0' ) ) ELSE
'0';
END ckt_d_conditional;
ARCHITECTURE ckt_d_selected OF ckt_d IS
SIGNAL ins : STD_LOGIC_VECTOR(0 TO 3);
BEGIN
ins <= A & B & C & D;
WITH ins SELECT
F <=
'1' WHEN "0001"|"0010",
'0' WHEN OTHERS;
END ckt_d_selected;
\end{lstlisting}
\end{minipage}
\begin{minipage}{1\linewidth}
\item
\begin{lstlisting}
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY and8 IS
PORT(
in0,in1,in2,in3,in4,in5,in6,in7 : IN STD_LOGIC;
out1 : OUT STD_LOGIC);
END and8;
ARCHITECTURE and8_concurrent OF and8 IS
BEGIN
out1 <= in0 AND in1 AND in2 AND in3 AND in4 AND in5 AND in6 AND in7;
END and8_concurrent;
ARCHITECTURE and8_conditional OF and8 IS
BEGIN
out1 <= '1' WHEN (in0 = '1' AND in1 = '1' AND in2 = '1' AND in3 = '1' AND in4 = '1' AND in5 = '1' AND in6 = '1' AND in7 = '1') ELSE
'0';
END and8_conditional;
ARCHITECTURE and8_selected OF and8 IS
SIGNAL ins : STD_LOGIC_VECTOR(0 TO 7);
BEGIN
ins <= in0 & in1 & in2 & in3 & in4 & in5 & in6 & in7;
WITH ins SELECT
out1 <=
'1' WHEN "11111111",
'0' WHEN OTHERS;
END and8_selected;
\end{lstlisting}
\end{minipage}
\begin{minipage}{1\linewidth}
\item
\begin{lstlisting}
LIBRARY IEEE;
USE IEEE_STD_LOGIC_1164.ALL;
ENTITY or8 IS
PORT(
ins : IN STD_LOGIC_VECTOR(7 DOWNTO 0);
out1 : OUT STD_LOGIC);
END or8;
ARCHITECTURE or8_concurrent OF or8 IS
BEGIN
out1 <= ins(1) OR ins(2) OR ins(3) OR ins(4) OR ins(5) OR ins(6) OR ins(7);
END or8_concurrent;
ARCHITECTURE or8_conditional OF or8 IS
BEGIN
out1 <= '1' WHEN (ins(1) = '1' OR ins(2) = '1' OR ins(3) = '1' OR ins(4) = '1' OR ins(5) = '1' OR ins(6) = '1' OR ins(7) = '1') ELSE
'0';
END or8_conditional;
ARCHITECTURE or8_selected OF or8 IS
BEGIN
WITH ins SELECT
out1 <=
'0' WHEN "00000000",
'1' WHEN OTHERS;
END or8_selected;
\end{lstlisting}
\end{minipage}
\begin{minipage}{1\linewidth}
\item
\begin{lstlisting}
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY mux8to1 IS
PORT(
inputs : IN STD_LOGIC_VECTOR(7 DOWNTO 0);
sel : IN STD_LOGIC_VECTOR(2 DOWNTO 0);
output : OUT STD_LOGIC);
END mux8to1;
ARCHITECTURE mux8to1_conditional OF mux8to1 IS
BEGIN
output <=
inputs(0) WHEN (sel = "000") ELSE
inputs(1) WHEN (sel = "001") ELSE
inputs(2) WHEN (sel = "010") ELSE
inputs(3) WHEN (sel = "011") ELSE
inputs(4) WHEN (sel = "100") ELSE
inputs(5) WHEN (sel = "101") ELSE
inputs(6) WHEN (sel = "110") ELSE
inputs(7) WHEN (sel = "111") ELSE
'0';
END mux8to1_conditional;
ARCHITECTURE mux8to1_selected OF mu8to1 IS
BEGIN
WITH sel SELECT
output <=
inputs(0) WHEN "000",
inputs(1) WHEN "001",
inputs(2) WHEN "010",
inputs(3) WHEN "011",
inputs(4) WHEN "100",
inputs(5) WHEN "101",
inputs(6) WHEN "110",
inputs(7) WHEN "111",
'0' WHEN OTHERS;
END mux8to1_selected;
\end{lstlisting}
\end{minipage}
\begin{minipage}{1\linewidth}
\item
\begin{lstlisting}
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY dec3to8_ActiveHigh IS
PORT (
inputs : IN STD_LOGIC_VECTOR(2 DOWNTO 0);
outputs : OUT STD_LOGIC_VECTOR(0 TO 7));
END dec3to8_ActiveHigh;
ARCHITECTURE dec3to8_ActiveHigh_conditional OF dec3to8_ActiveHigh IS
BEGIN
outputs <=
"10000000" WHEN (inputs = "000") ELSE
"01000000" WHEN (inputs = "001") ELSE
"00100000" WHEN (inputs = "010") ELSE
"00010000" WHEN (inputs = "011") ELSE
"00001000" WHEN (inputs = "100") ELSE
"00000100" WHEN (inputs = "101") ELSE
"00000010" WHEN (inputs = "110") ELSE
"00000001" WHEN (inputs = "111") ELSE
"00000000";
END dec3to8_ActiveHigh_conditional;
ARCHITECTURE dec3to8_ActiveHigh_selected OF dec3to8_ActiveHigh IS
BEGIN
WITH inputs SELECT
outputs <=
"10000000" WHEN "000",
"01000000" WHEN "001",
"00100000" WHEN "010",
"00010000" WHEN "011",
"00001000" WHEN "100",
"00000100" WHEN "101",
"00000010" WHEN "110",
"00000001" WHEN "111",
"00000000" WHEN OTHERS;
END dec3to8_ActiveHigh_selected;
\end{lstlisting}
\end{minipage}
\begin{minipage}{1\linewidth}
\item
\begin{lstlisting}
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY dec3to8_ActiveLow IS
PORT (
inputs : IN STD_LOGIC_VECTOR(2 DOWNTO 0);
outputs : OUT STD_LOGIC_VECTOR(0 TO 7));
END dec3to8_ActiveLow;
ARCHITECTURE dec3to8_ActiveLow_conditional OF dec3to8_ActiveLow IS
BEGIN
outputs <=
"01111111" WHEN (inputs = "000") ELSE
"10111111" WHEN (inputs = "001") ELSE
"11011111" WHEN (inputs = "010") ELSE
"11101111" WHEN (inputs = "011") ELSE
"11110111" WHEN (inputs = "100") ELSE
"11111011" WHEN (inputs = "101") ELSE
"11111101" WHEN (inputs = "110") ELSE
"11111110" WHEN (inputs = "111") ELSE
"11111111";
END dec3to8_ActiveLow_conditional;
ARCHITECTURE dec3to8_ActiveLow_selected OF dec3to8_ActiveLow IS
BEGIN
WITH inputs SELECT
outputs <=
"01111111" WHEN "000",
"10111111" WHEN "001",
"11011111" WHEN "010",
"11101111" WHEN "011",
"11110111" WHEN "100",
"11111011" WHEN "101",
"11111101" WHEN "110",
"11111110" WHEN "111",
"11111111" WHEN OTHERS;
END dec3to8_ActiveLow_selected;
\end{lstlisting}
\end{minipage}
\end{enumerate}
\section*{Chapter 5}
\begin{enumerate}
\item a)
\begin{lstlisting}
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY ckt_a IS
PORT(
A,B : IN STD_LOGIC;
F : OUT STD_LOGIC);
END ckt_a;
ARCHITECTURE ckt_a_case OF ckt_a IS
SIGNAL ins : STD_LOGIC_VECTOR(0 TO 1);
BEGIN
ins <= A & B;
logic_process: PROCESS(ins)
BEGIN
CASE (ins) IS
WHEN "01" =>
F <= '1';
WHEN "10" =>
F <= '1';
WHEN "11" =>
F <= '1';
WHEN OTHERS =>
F <= '0';
END CASE;
END PROCESS logic_process;
END ckt_a_case;
ARCHITECTURE ckt_a_if OF ckt_a IS
BEGIN
logic_process: PROCESS(A,B)
BEGIN
IF (A = '0' AND B = '1') THEN
F <= '1';
ELSIF (A = '1') THEN
F <= '1';
ELSE
F <= '0';
END IF;
END PROCESS logic_process;
END ckt_a_if;
\end{lstlisting}
b)
\begin{lstlisting}
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY ckt_b IS
PORT(
A,B,C,D : IN STD_LOGIC;
F : OUT STD_LOGIC);
END ckt_b;
ARCHITECTURE ckt_b_case OF ckt_b IS
SIGNAL ins : STD_LOGIC_VECTOR(0 TO 3);
BEGIN
ins <= A & B & C & D;
logic_process: PROCESS(ins)
BEGIN
CASE (ins) IS
WHEN "0010" =>
F <= '1';
WHEN "0110" =>
F <= '1';
WHEN "0011" =>
F <= '1';
WHEN "1010" =>
F <= '1';
WHEN "1011" =>
F <= '1';
WHEN "1110" =>
F <= '1';
WHEN OTHERS =>
F <= '0';
END CASE;
END PROCESS logic_process;
END ckt_b_case;
ARCHITECTURE ckt_b_if OF ckt_b IS
BEGIN
logic_process: PROCESS(A,B,C,D)
BEGIN
IF ( A = '0' AND C = '1' AND D = '1' ) THEN
F <= '1';
ELSIF ( B = '0' AND C = '1' ) THEN
F <= '1';
ELSIF ( B = '1' AND C = '1' AND D = '0' ) THEN
F <= '1';
ELSE
F <= '0';
END IF;
END PROCESS logic_process;
END ckt_b_if;
\end{lstlisting}
c)
\begin{lstlisting}
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY ckt_c IS
PORT(
A,B,C,D : IN STD_LOGIC;
F : OUT STD_LOGIC);
END ckt_c;
ARCHITECTURE ckt_c_case OF ckt_c IS
SIGNAL ins : STD_LOGIC_VECTOR(0 TO 3);
BEGIN
ins <= A & B & C & D;
logic_process: PROCESS(ins)
BEGIN
CASE (ins) IS
WHEN "0000" =>
F <= '1';
WHEN "0001" =>
F <= '1';
WHEN "0010" =>
F <= '1';
WHEN "0011" =>
F <= '1';
WHEN "0100" =>
F <= '1';
WHEN "0110" =>
F <= '1';
WHEN "0111" =>
F <= '1';
WHEN "1111" =>
F <= '1';
WHEN OTHERS =>
F <= '0';
END CASE;
END PROCESS logic_process;
END ckt_c_case;
ARCHITECTURE ckt_c_if OF ckt_c IS
BEGIN
logic_process: PROCESS(A,B,C,D)
BEGIN
IF ( ( A = '0' OR B = '1' ) AND ( B = '0' OR C = '1' OR D = '0' ) AND ( A = '0' OR D = '1' ) ) THEN
F <= '1';
ELSE
F <= '0';
END IF;
END PROCESS logic_process;
END ckt_c_if;
\end{lstlisting}
d)
\begin{lstlisting}
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY ckt_d IS
PORT(
A,B,C,D : IN STD_LOGIC;
F : OUT STD_LOGIC);
END ckt_d;
ARCHITECTURE ckt_d_case OF ckt_d IS
SIGNAL ins : STD_LOGIC_VECTOR(0 TO 3);
BEGIN
ins <= A & B & C & D;
logic_process: PROCESS(ins)
BEGIN
CASE (ins) IS
WHEN "0001" =>
F <= '0';
WHEN "0011" =>
F <= '0';
WHEN "0100" =>
F <= '0';
WHEN "0101" =>
F <= '0';
WHEN OTHERS =>
F <= '1';
END CASE;
END PROCESS logic_process;
END ckt_d_case;
ARCHITECTURE ckt_d_if OF ckt_d IS
BEGIN
logic_process: PROCESS(A,B,C,D)
BEGIN
IF ( A = '0' AND B = '0' AND C = '0' AND D = '1' ) THEN
F <= '0';
ELSIF ( A = '1' AND B = '1' AND C = '1' AND D = '1' ) THEN
F <= '0';
ELSIF ( A = '0' AND B = '1' AND C = '0' AND D = '0' ) THEN
F <= '0';
ELSIF ( A = '0' AND B = '1' AND C = '0' AND D = '1' ) THEN
F <= '0';
ELSE
F <= '1';
END IF;
END PROCESS logic_process;
END ckt_d_if;
\end{lstlisting}
e)
\begin{lstlisting}
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY ckt_e IS
PORT(
A,B,C,D : IN STD_LOGIC;
F : OUT STD_LOGIC);
END ckt_e;
ARCHITECTURE ckt_e_case OF ckt_e IS
SIGNAL ins : STD_LOGIC_VECTOR(0 TO 3);
BEGIN
ins <= A & B & C & D;
logic_process: PROCESS(ins)
BEGIN
CASE (ins) IS
WHEN "0001" =>
F <= '1';
WHEN "0010" =>
F <= '1';
WHEN OTHERS =>
F <= '0';
END CASE;
END PROCESS logic_process;
END ckt_e_case;
ARCHITECTURE ckt_e_if OF ckt_e IS
BEGIN
logic_process: PROCESS(A,B,C,D)
BEGIN
IF ( A = '0' AND B = '0' AND C = '0' AND D = '1' ) THEN
F <= '1';
ELSIF ( A = '0' AND B = '0' AND C = '1' AND D = '0' ) THEN
F <= '1';
ELSE
F <= '0';
END IF;
END PROCESS logic_process;
END ckt_e_if;
\end{lstlisting}
\item
\begin{lstlisting}
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY Exercise_5_2 IS
PORT(
A,B : IN STD_LOGIC_VECTOR(1 DOWNTO 0);
D : IN STD_LOGIC;
E_out : OUT STD_LOGIC);
END Exercise_5_2;
ARCHITECTURE Exercise_5_2_case OF Exercise_5_2 IS
SIGNAL Aout,Bout,Cout,Dout : STD_LOGIC;
SIGNAL Cin : STD_LOGIC_VECTOR(0 TO 1);
SIGNAL Ein : STD_LOGIC_VECTOR(0 TO 2);
BEGIN
Cin <= B(2) & Dout;
Ein <= Aout & Bout & Cout;
devA: PROCESS(A)
BEGIN
CASE (A) IS
WHEN "00"|"01"|"10" =>
Aout <= '0';
WHEN "11" =>
Aout <= '1';
END CASE;
END PROCESS devA;
devB: PROCESS(B)
BEGIN
CASE(B) IS
WHEN "00" =>
Bout <= '0';
WHEN "01"|"10"|"11" =>
Bout <= '1';
END CASE;
END PROCESS devB;
devC: PROCESS(Cin)
BEGIN
CASE(Cin) IS
WHEN "00"|"01"|"10" =>
Cout <= '0';
WHEN "11" =>
Cout <= '1';
END CASE;
END PROCESS devC;
devD: PROCESS(D)
BEGIN
CASE(D) IS
WHEN '0' =>
Dout <= '1';
WHEN '1' =>
Dout <= '0';
END CASE;
END PROCESS devD;
devE: PROCESS(Ein) IS
BEGIN
CASE (Ein) IS
WHEN "000" =>
E_out <= '0';
WHEN OTHERS =>
E_out <= '1';
END CASE;
END PROCESS devE;
END Exercise_5_2_case;
ARCHITECTURE Exercise_5_2_if OF Exercise_5_2 IS
BEGIN
logic_process: PROCESS(A,B,D) IS
BEGIN
IF ( A = "11") THEN
E_out <= '1';
ELSIF ( B = "01"|"10"|"11" ) THEN
E_out <= '1';
ELSIF ( B(2) = '1' AND D = '0' ) THEN
E_out <= '1';
ELSE
E_out <= '0';
END IF;
END PROCESS logic_process;
END Exercise_5_2_if;
\end{lstlisting}
\item
\begin{lstlisting}
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY Exercise_5_3 IS
PORT(
A,B : IN STD_LOGIC_VECTOR(1 DOWNTO 0);
D : IN STD_LOGIC;
E_out : OUT STD_LOGIC);
END Exercise_5_3;
ARCHITECTURE Exercise_5_3_arc OF Exercise_5_3 IS
SIGNAL Aout,Bout,Cout,Dout : STD_LOGIC;
BEGIN
Aout <= A(1) AND A(2);
Bout <= B(1) OR B(2);
Cout <= B(2) AND Dout;
Dout <= NOT D;
E_out <= Aout OR Bout OR Cout;
END Exercise_5_3_arc;
\end{lstlisting}
\item
\begin{lstlisting}
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY and8 IS
PORT(
ins : IN STD_LOGIC_VECTOR(7 DOWNTO 0);
out1 : OUT STD_LOGIC);
END and8;
ARCHITECTURE and8_arc OF and8 IS
BEGIN
logic_process: PROCESS(ins)
BEGIN
IF ( ins = "11111111" ) THEN
out1 <= '1';
ELSE
out1 <= '0';
END IF;
END PROCESS logic_process;
END and8_arc;
\end{lstlisting}
\item
\begin{lstlisting}
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY or8 IS
PORT(
ins : IN STD_LOGIC_VECTOR(7 DOWNTO 0);
out1 : OUT STD_LOGIC);
END or8;
ARCHITECTURE or8_arc OF or8 IS
BEGIN
logic_process: PROCESS(ins)
BEGIN
IF ( ins = "00000000" ) THEN
out1 <= '0';
ELSE
out1 <= '1';
END IF;
END PROCESS logic_process;
END or8_arc;
\end{lstlisting}