![Page 1: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/1.jpg)
1
Struttura generale del decoder
Tipicamente n input, m=2n outputs
2-to-4, 3-to-8, 4-to-16, etc.
Decoder
Circuito che converte un codice di input a nbit in un codice di output a m bit.
![Page 2: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/2.jpg)
2
![Page 3: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/3.jpg)
3
Circuito da-n-a-2n
Codice 1-fra-m:contiene m bit con un solo bit asserito ad ogni istante
Decoder da-2-a-4:
Si noti la notazione “x” (don’t care)
Decoder binari
![Page 4: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/4.jpg)
4
![Page 5: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/5.jpg)
5
Diagramma logico del decoder da-2-a-4 con enable
![Page 6: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/6.jpg)
6
• Buffer di input (meno carico)• gate NAND (più veloci)
Decoder da-2-a-4 in logica negativa
![Page 7: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/7.jpg)
7
Decoder da-3-a-8
3-to-8Line
Decoder
y0 = a’b’c’y1 = a’b’cy2 = a’bc’y3 = a’bcy4 = ab’c’y5 = ab’cy6 = abc’y7 = abc
abc
a b c Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 1 0 0 0 1 0 0 0 0 0 1 0 0 0 0 1 0 1 0 0 1 0 0 0 0 0 1 1 0 0 1 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0
+
![Page 8: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/8.jpg)
8
Decoder da-3-a-8 con codice di input Gray
3-to-8Line
Decoder
DEG0DEG45DEG135DEG90DEG315DEG270DEG180DEG225
abc
Il codice di input non rappresenta necessariamente gli interi da 0 a 2n-1.
Supponiamo che il codice di input sia il codice Gray di un disco di codifica meccanica con otto posizioni.
Posizione del disco I2 I1 I0 output del decoder binario 0o 0 0 0 Y0 45o
0 0 1 Y1 90o 0 1 1 Y3 135o 0 1 0 Y2 180o 1 1 0 Y6 225o 1 1 1 Y7 270o 1 0 1 Y5 315o 1 0 0 Y4
![Page 9: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/9.jpg)
9
Decoder da-3-a-8 74x138
![Page 10: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/10.jpg)
10
Decoder da-2-a-4 controllato da un contatore a 2 bit
![Page 11: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/11.jpg)
11
![Page 12: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/12.jpg)
12
![Page 13: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/13.jpg)
13
– Memoria dei microprocessori• Selezione di diversi banchi di memoria
– Sistemi di input/output di microprocessori• Selezione di diversi dispositivi
– Decodifica di istruzioni di microprocessori• Abilitazione di diverse unità funzionali
– Chips di memoria• Abilitazione di diverse righe di memoria a seconda dell’indirizzo
– Moltissime altre applicazioni
Applicazioni dei decoder
![Page 14: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/14.jpg)
14
Decoder in verilog
![Page 15: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/15.jpg)
15
multiplexing
Multiplexing nella forma più semplice: un tasto (switch) meccanico capace di selezionare fra diverse sorgenti
Sorgenti: 4 microfoni che inviano a una stazione remota di ascolto della polizia segrenta
Una volta al mese un agente segreto agisce sul tasto per ascoltare uno dei microfoni
![Page 16: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/16.jpg)
16
Sistema telefonico
Sistema di periferiche collegate a un computer
Sistema multiplexato
![Page 17: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/17.jpg)
17
Multiplexing: hardware
Sono necessari due elementi:
1. circuito passa/blocca analogo al tasto chiuso/aperto
2. circuito di decodifica che chiuderà solo uno degli elementi passa/blocca per volta
pass/block’ segnale-in segnale-out 0 0 0 0 1 0 1 0 0 1 1 1
IN
pass/block’OUT
gate AND
pass/block
Multiplexer 2-to-1
![Page 18: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/18.jpg)
18
Il MUX più semplice:
![Page 19: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/19.jpg)
19
Mux a quattro input
Circuito che fa “collega” uno dei quattro input all’ouput out a seconda del valore delle due linee di selezione SEL[1..0]
![Page 20: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/20.jpg)
20
Mux a quattro input
Decoder da-2-a-4
Z
OR dei segnali
IN0
EN0
IN1
EN1
IN2
EN2
IN3
EN3
Circuiti passa/blocca
![Page 21: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/21.jpg)
21
Progetto 2
Esempio di utilizzo di multiplexer e decoder
![Page 22: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/22.jpg)
22seven-seg-decoder
![Page 23: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/23.jpg)
23
FPGA
seven-seg-decoder
Dalla FPGA escono solo 7 linee di controllo dei led comuni ai 4 array
E’ necessario interporre un MUX fra i 4 seven-seg-decoder e le linee di uscita
![Page 24: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/24.jpg)
24
![Page 25: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/25.jpg)
25
una cifra diversa
![Page 26: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/26.jpg)
26
![Page 27: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/27.jpg)
27
![Page 28: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/28.jpg)
28
![Page 29: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/29.jpg)
29
![Page 30: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/30.jpg)
30
![Page 31: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/31.jpg)
31
![Page 32: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/32.jpg)
32
![Page 33: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/33.jpg)
33
I0
I1
I2
I3
A B Z 0 0 1 0 1 0 1 0 T 1 1 T
+
A B
Z
Esempio: implementiamo la funzione F(R, S, T) = R’S’ + RT
F(R,S,T) = R’S’•1 + RT•(S+S’)
= R’S’•1 + R’S•0 + RS•T + RS’•T
R S
F(R,S,T)
T
T
1
0
Functions of how many input variablescan be implemented by an 8-t0-1 MUX?
Utilizzare un 8-to-1 MUX per implementare la funzione: F(X,Y,Z,T) = XY’ + Z’T
00 01 11 10
Un mux a quattro input può implementare qualunque funzione a tre variabili
![Page 34: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/34.jpg)
34
Implementazione “tradizionale”
Come implementare la funzione logica con un mux?
![Page 35: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/35.jpg)
35
![Page 36: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/36.jpg)
36
![Page 37: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/37.jpg)
37
![Page 38: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/38.jpg)
38
CPU
Consideriamo una serie di dispositivi collegati a una CPU tramite una linea comune (bus)
La CPU può abilitare uno dei dispositivi per volta che accede al bus trasmettendo dati
EN0 EN1
EN2 EN3
EN0=1 EN1=1EN0=0
MUX a quattro input?
out0 out1
out2 out3
out0 out1out0
Tristate
![Page 39: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/39.jpg)
39
IN0
EN0
IN1
EN1
IN2
EN2
IN3
EN3
output sul bus?
NO!
Come facciamo a fare MUX?
Problema: è impossibile mettere in OR OUT0, ..., OUT3
![Page 40: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/40.jpg)
40
Le uscite del gate logici che abbiamo studiato finora non possono essere collegate assieme
I gate si “sparano” uno contro l’altro
![Page 41: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/41.jpg)
41
Come facciamo a fare MUX?
Andrebbe bene un sistema tale che se un dispositivo non è abilitato è come se non fosse fisicamente collegato al bus
CPU
EN1
EN2 EN3
EN0=1
out0 out1
out2 out3
EN1=1EN0=0
out1out0
buffer tristate:
A OUT
ENEN A OUT L L Hi-Z L H Hi-Z H L L H H H
Hi-Z: alta impedenza
linea scollegata
![Page 42: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/42.jpg)
42
![Page 43: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/43.jpg)
43
![Page 44: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/44.jpg)
44
output sul bus?
data0
EN0
data1
EN1
data2
EN2
data3
EN3
SI!
Mux con buffers tristate
out0
out1
out2
out3
periferica
data## dati che la periferica ## trasmette se richiesto (EN## asserito dalla CPU)
![Page 45: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/45.jpg)
45
Tristate party line col 74x138
![Page 46: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/46.jpg)
46
Per impedire conflitti, dovrebbero andare nello stato Hi-Z più velocemente di quanto impiegano per andare nello stato Hi-Z
(tpLZ e tpHZ dovrebbero essere minori di tpZL tpZH)
Considerazioni sulla temporizzazione
![Page 47: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/47.jpg)
47
Per sicurezza, la logica di controllo dovrebbe garantire un tempo morto sulla party line durante il quale nessuno pilota la linea.
![Page 48: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/48.jpg)
48
Parte importante del percorso dei dati nell’architettura di una CPU
Come tutto l’hardware, può essere disegnata usando un linguaggio di programmazione orientato all’hardware (HDL)
Utile esempio perchè può essere facilmente decomposta
ALU
ALU operation
operand1
operand2
alu_result
opcode
Esempio motivante: l’unità logico-aritmetica (ALU)
![Page 49: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/49.jpg)
49
Esempio motivante: l’unità logico-aritmetica (ALU)
• Insieme di operazioni:
Arithmetic • add• subtract• multiply• negate
Logic • AND• OR• XOR• NOT
ALU
ALU operation
operand1
operand2
alu_result
opcode
![Page 50: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/50.jpg)
50
1
arithmeticoperation
logicoperation
MUX
Modulo aritmetico
Modulo logico
operand1
operand0
Arith_result
Logic_result
selection
Alu_result
opcode
2
Struttura della ALU
![Page 51: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/51.jpg)
51
1
MUX
ModuloAritmetico
Modulologico
operand1
operand0
Arith_result
Logic_result
selection
Alu_result
opcode
2
ALU
Struttura della ALU
![Page 52: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/52.jpg)
52
• Disegni organizzati gerarchicamente• Ciascun elemento del disegno ha:
– Un’interfaccia ben definita– Una precisa specifica del comportamento usando o:
• Una descrizione algoritmica• Una descrizione strutturale dell’hardware
• Modella la concorrenza, la temporizzazione, e il clock:– Gestisce circuiti asincroni e sincroni– I disegni possono essere simulati
VERILOG HDL
![Page 53: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/53.jpg)
53
alu_arch
alu
arithmetic_module_arch
arithmetic_module
ArithmeticFunctionality
logic_module_arch
logic_module
LogicFunctionality
mux_arch
mux
Multiplexer
Struttura gerarchica della ALU
Procedura bottom-up: cominciamo a modellare gli elementi più in basso
![Page 54: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/54.jpg)
54
Mux: introduzione ai moduli e porte
MUX
Arith_result
Logic_result
Alu_result
selection
Il blocco costruttivo fondamentale di verilog è il modulo
elemento o collezione di blocchi di livello più basso.
module mux(Arith_result, Logic_result, Alu_result);
Dichiarazione varibili…Funzionalità
endmodule;
Sintassi:
![Page 55: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/55.jpg)
55
MUX
Arith_result
Alu_result
selection
module mux(Arith_result, Logic_result, selection, Alu_result);
funzionalità…
endmodule;
Sintassi:Logic_result
porte
Dichiarazione di variabili: segnali di input e output
module mux(Arith_result, Logic_result, selection, Alu_result);
input Arith_result, Logic_result,Alu_result;…
endmodule;
Segnali di input: Arith_result, Logic_result, selection
module mux(Arith_result, Logic_result, selection, Alu_result);
input Arith_result, Logic_result,selection;output Alu_result;
…endmodule;
Segnale di output: Alu_result
![Page 56: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/56.jpg)
56
Verilog supporta i gate logici fondamentali come moduli primitivi predefiniti.
Arith_result
Alu_result
selection
Logic_result
selection selection_na0
a1
net: connessioni fra elementi hardware
Le net sono dichiarate con la keyword wire.
Hanno valori pilotati continuamente dagli output dei dispositivi cui sono collegate
module mux(Arith_result, Logic_result, selection, Alu_result);
input Arith_result, Logic_result,selection;output Alu_result;
wire selection_n, a0, a1; …
endmodule;Gli input e output del modulo sono implicitamente wire
Disegno a livello di gate
![Page 57: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/57.jpg)
57
module mux(Arith_result, Logic_result, selection, Alu_result);
input Arith_result, Logic_result,selection;output Alu_result;
wire selection_n, a0, a1; …
endmodule;
Instanziamento dei moduli primitivi
Arith_result
Alu_result
selection
Logic_result
selection selection_na0
a1
module mux(Arith_result, Logic_result, selection, Alu_result);
input Arith_result, Logic_result,selection;output Alu_result;
wire selection_n, a0, a1;
not (selection_n,selection); endmodule;
module mux(Arith_result, Logic_result, selection, Alu_result);
input Arith_result, Logic_result,selection;output Alu_result;
wire selection_n, a0, a1;
not (selection_n,selection);and (a1,selection,Arith_result);
endmodule;
module mux(Arith_result, Logic_result, selection, Alu_result);
input Arith_result, Logic_result,selection;output Alu_result;
wire selection_n, a0, a1;
not (selection_n,selection);and (a1,selection,Arith_result); and (a0,selection_n,Logic_result);
endmodule;
module mux(Arith_result, Logic_result, selection, Alu_result);
input Arith_result, Logic_result,selection;output Alu_result;
wire selection_n, a0, a1;
not (selection_n,selection);and (a1,selection,Arith_result); and (a0,selection_n,Logic_result); or (Alu_result,a0,a1);
endmodule;
![Page 58: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/58.jpg)
58
module mux(Arith_result, Logic_result, selection, Alu_result);
input Arith_result, Logic_result,selection;output Alu_result;
wire selection_n, a0, a1; …
endmodule;
Metodo di instanziamento alternativo
Arith_result
Alu_result
selection
Logic_result
selection selection_na0
a1
module mux(Arith_result, Logic_result, selection, Alu_result);
input Arith_result, Logic_result,selection;output Alu_result;
wire selection_n, a0, a1;
not (selection_n,selection); endmodule;
module mux(Arith_result, Logic_result, selection, Alu_result);
input Arith_result, Logic_result,selection;output Alu_result;
wire selection_n, a0, a1;
not (selection_n,selection);and (a1,selection,Arith_result);
endmodule;
module mux(Arith_result, Logic_result, selection, Alu_result);
input Arith_result, Logic_result,selection;output Alu_result;
wire selection_n, a0, a1;
not (selection_n,selection);and (a1,selection,Arith_result); and (a0,selection_n,Logic_result);
endmodule;
module mux(Arith_result, Logic_result, selection, Alu_result);
input Arith_result, Logic_result,selection;output Alu_result;
wire selection_n, a0, a1;
not not1(selection_n,selection);and and1(a1,selection,Arith_result); and and0(a0,selection_n,Logic_result); or or1(Alu_result,a0,a1);
endmodule;
![Page 59: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/59.jpg)
59
Un maggiore livello di astrazione: modellazione del flusso dei dati (dataflow)
Modellazione a livello di gate: intuitivo tuttavia non efficiente per componenti con un numero di gate grande.
Modellazione del flusso dei dati: rappresentazione di un circuito in termini del flusso dei dati fra input e output a un livello più astratto
Assegnazione continua assign: istruzione fondamentale per pilotare un valore su una net:
wire Z1; assign Z1 = operazione logica su X1, X2, …
X1, X2, ... = operandi
Operazione logica: operatore
X1
Xm
X2
Z1
Zm
Z2
Funzionamento specificato non in termini di gate elementari
![Page 60: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/60.jpg)
60
AND: assign Z1 = X1 & X2;
Operazioni logiche su coppie di operandi
OR: assign Z1 = X1 | X2;
NOT: assign Z1 = ~ X1;
Alu_result
a0
a1
assign Alu_result = a0 | a1;
Arith_result
selection
assign a1 = selection & Arith_result
a1
Logic_result
selection selection_n
assign a0 = ~ selection & Logic_result
a0
module mux(Arith_result, Logic_result, selection, Alu_result);
input Arith_result, Logic_result,selection;output Alu_result;
assign Alu_result = (~ selection & Logic_result) | (selection & Arith_result);
endmodule;
![Page 61: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/61.jpg)
61
assign Alu_result = selection ? Arith_result : Logic_result;
Operatore condizionale
module mux(Arith_result, Logic_result, selection, Alu_result);
input Arith_result, Logic_result,selection;output Alu_result;
assign Alu_result = selection ? Arith_result : Logic_result;
endmodule;
Espressione condizione:
Se vera (1) Alu_result = Arith_result
Se falsa (0) Alu_result = Logic_result
![Page 62: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/62.jpg)
62
Vettori
ALU a 8 bit: Arith_result, Logic_result e ALU_result sono numeri a 8 bit
module mux(Arith_result, Logic_result, selection, Alu_result);
input [7:0] Arith_result, Logic_result,selection;output [7:0] Alu_result;
assign Alu_result = selection ? Arith_result : Logic_result;
endmodule;
Arith_result Arith_result[7:0]
Logic_result Logic_result[7:0]
ALU_result ALU_result[7:0]
![Page 63: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/63.jpg)
63
Modulo aritmetico
operand1
opcode
operand0 Arith_result
Operandi: vettori a 8 bit
opcode: 4 operazioni vettore a 2 bit module arith_module(operand0,
operand1, opcode, Arith_result);
input [7:0] operand0, operand1;output [7:0] Arith_result; input [1:0] opcode;wire [7:0] zero = 32’b0;…
endmodule;
Operazioni:
opcode = 0 Arith_result = operand0 + operand1
opcode = 1 Arith_result = operand0 - operand1
opcode = 2 Arith_result = zero – operand0
opcode = 3 Arith_result = operand0 * operand1
module arith_module(operand0, operand1, opcode, Arith_result);
input [7:0] operand0, operand1;output [7:0] Arith_result; input [1:0] opcode;wire [7:0] zero = 8’b0;
wire [7:0] op0 = operand1 + operand0;wire [7:0] op1 = operand1 – operand0;wire [7:0] op2 = zero – operand0;wire [7:0] op3 = operand1 * operand1;
…
endmodule;
![Page 64: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/64.jpg)
64
Le quattro operazioni devono essere multiplexate mux 1 di 4 con operatori condizionali annidati
module arith_module(operand0, operand1, opcode, Arith_result);
input [7:0] operand0, operand1;output [7:0] Arith_result; input [1:0] opcode;wire [7:0] zero = 8’b0;
wire [7:0] op0 = operand1 + operand0;wire [7:0] op1 = operand1 – operand0;wire [7:0] op2 = zero – operand0;wire [7:0] op3 = operand1 * operand1;
assign Arith_result = opcode[1] ? (opcode[0] ? op3 : op2) : (opcode[0] ? op1 : op0);
endmodule;
![Page 65: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/65.jpg)
65
Variabili di tipo registro (reg)
I registri rappresentano elementi di memorizzazione dati (data storage)
Mantengono il loro valore finchè un altro valore è posto su essi
A differenza di una net un registro non necessita un driver e non sono pilotati continuamente
Non devono essere confusi con i registri hardware costruiti con flip-flop D e che possono cambiare il loro valore solo sul bordo di un clock possono cambiare valore a un istante qualsiasi.
Sono dichiarati con la keyword reg.
netreg o net
net
input
reg o net
output
modulo
![Page 66: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/66.jpg)
66
Statement alwaysalways @(condizione) begin … end
Ogni volta che è soddisfatta la condizione in parentesi, vengono eseguiti tutti gli stament contenuti all’interno del blocco begin-end
Blocco begin-end: analogo a un raggruppamento di istruzioni {} del linguaggio di programmazione C.
always @(clk) q=d q=d è eseguito ogni volta che il segnale clk cambia valore
q=d è eseguito ogni volta che il segnale clk compie una transizione negativa
always @(negedge clk) q=d
always @(posedge clk) q=d q=d è eseguito ogni volta che il segnale clk compie una transizione positiva
![Page 67: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/67.jpg)
67
Possono essere presenti più blocchi always in un modulo:
tutti i blocchi funzionano simultaneamente e in modo concorrenziale
caratteristica fondamentale del funzionamento dei componenti hardware
caratteristica distintiva di Verilog rispetto a un linguaggio come il C in cui tutte le istruzioni sono eseguite in modo sequenziale
La variabile q a cui è assegnato d a ogni bordo negativo del segnale clk deve essere necessariamente di tipo reg
deve mantenere il valore fra due istanti in cui si verifica la condizione negedge clk
always @(negedge clk) q=d
![Page 68: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/68.jpg)
68
Statement case
sintassi
case(espressione) alternativa 0: statement 0; alternativa 1: statement 1;… endcase
L’espressione è confrontata alle alternative nell’ordine in cui appaiono
Per la prima alternativa per cui c’e’ accordo il corrispondente statement o blocco è eseguito
![Page 69: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/69.jpg)
69
module arith_module(operand0, operand1, opcode, Arith_result);
input [7:0] operand0, operand1;output [7:0] Arith_result; reg [7:0] Arith_result;input [1:0] opcode;wire [7:0] zero = 8’b0;
always @(operand0 or operand1 or opcode) case(opcode) 2’d0: Arith_result = operand1 + operand0; 2’d1 Arith_result = operand1 – operand0; 2’d2 Arith_result = zero – operand0; 2’d3 Arith_result = operand1 * operand1; endcase
endmodule;
Esecuzione triggerata da una transizione di uno qualsiasi dei segnali operand o opcode
always @(segnale0 or segnale1 or …)
![Page 70: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/70.jpg)
70
Abbellimenti
Assegamo un nome alle varie operazioni:
module arith_module(operand0, operand1, opcode, Arith_result);
`define Add 2’d0;input [7:0] operand0, operand1;output [7:0] Arith_result; reg [7:0] Arith_result;input [1:0] opcode;wire [7:0] zero = 8’b0;
always @(operand0 or operand1 or opcode)case(opcode) `Add : Arith_result = operand1 + operand0;
endcase
endmodule;
Opcode = 2’b0 Add
Opcode = 2’d1 Sub
module arith_module(operand0, operand1, opcode, Arith_result);
`define Add 2’d0;`define Sub 2’d1;
input [7:0] operand0, operand1;output [7:0] Arith_result; reg [7:0] Arith_result;input [1:0] opcode;wire [7:0] zero = 8’b0;
always @(operand0 or operand1 or opcode)case(opcode) `Add : Arith_result = operand1 + operand0; `Sub : Arith_result = operand1 – operand0;
endcase
endmodule;
Opcode = 2’d2 Neg
module arith_module(operand0, operand1, opcode, Arith_result);
`define Add 2’d0;`define Sub 2’d1;`define Neg 2’d2;
input [7:0] operand0, operand1;output [7:0] Arith_result; reg [7:0] Arith_result;input [1:0] opcode;wire [7:0] zero = 8’b0;
always @(operand0 or operand1 or opcode)case(opcode) `Add : Arith_result = operand1 + operand0; `Sub : Arith_result = operand1 – operand0;`Neg : Arith_result = zero – operand0;
endcase
endmodule;
Opcode = 2’d3 Mult
module arith_module(operand0, operand1, opcode, Arith_result);
`define Add 2’d0;`define Sub 2’d1;`define Neg 2’d2;`define Mult 2’d3;
input [7:0] operand0, operand1;output [7:0] Arith_result; reg [7:0] Arith_result;input [1:0] opcode;wire [7:0] zero = 8’b0;
always @(operand0 or operand1 or opcode)case(opcode) `Add : Arith_result = operand1 + operand0; `Sub : Arith_result = operand1 – operand0; `Neg : Arith_result = zero – operand0; `Mult : Arith_result = operand1 * operand0;
endcase
endmodule;
![Page 71: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/71.jpg)
71
Generalizzare il codice
Il nostro progetto richiede una ALU a 8 bit. Un upgrade potrebbe richiedere la processazione di numeri a 16 bit.
modulo generico funzionante in entrambi i casi con modifiche minime
module arith_module(operand0, operand1, opcode, Arith_result);
`define ALU_width 8;
`define Add 2’d0;`define Sub 2’d1;`define Neg 2’d2;`define Mult 2’d3;
input [`ALU_width-1:0] operand0, operand1;output [`ALU_width-1:0] Arith_result; reg [`ALU_width-1:0] Arith_result;input [1:0] opcode;wire [`ALU_width-1:0] zero = 8’b0;
always @(operand0 or operand1 or opcode)case(opcode) `Add : Arith_result = operand1 + operand0; `Sub : Arith_result = operand1 – operand0; `Neg : Arith_result = zero – operand0; `Mult : Arith_result = operand1 * operand0;
endcase
endmodule;
Dobbiamo cambiare la larghezza in un solo punto
![Page 72: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/72.jpg)
72
Modulo logico
struttura simile al modulo aritmetico
module arith_module(operand0, operand1, opcode, Arith_result);
`define ALU_width 8;
`define AND 2’d0;
input [`ALU_width-1:0] operand0, operand1;output [`ALU_width-1:0] Arith_result; reg [`ALU_width-1:0] Arith_result;input [1:0] opcode;wire [`ALU_width-1:0] zero = 8’b0;
always @(operand0 or operand1 or opcode)case(opcode) `AND : Arith_result = operand1 & operand0; endcase
endmodule;
AND
OR
module arith_module(operand0, operand1, opcode, Arith_result);
`define ALU_width 8;
`define AND 2’d0;`define OR 2’d1;
input [`ALU_width-1:0] operand0, operand1;output [`ALU_width-1:0] Arith_result; reg [`ALU_width-1:0] Arith_result;input [1:0] opcode;wire [`ALU_width-1:0] zero = 8’b0;
always @(operand0 or operand1 or opcode)case(opcode) `AND : Arith_result = operand1 & operand0; `OR : Arith_result = operand1 | operand0; endcase
endmodule;
XOR
module arith_module(operand0, operand1, opcode, Arith_result);
`define ALU_width 8;
`define AND 2’d0;`define OR 2’d1;`define XOR 2’d2;
input [`ALU_width-1:0] operand0, operand1;output [`ALU_width-1:0] Arith_result; reg [`ALU_width-1:0] Arith_result;input [1:0] opcode;wire [`ALU_width-1:0] zero = 8’b0;
always @(operand0 or operand1 or opcode)case(opcode) `AND : Arith_result = operand1 & operand0; `OR : Arith_result = operand1 | operand0; `XOR : Arith_result = operand0 ^ operand1; endcase
endmodule;
NOT
module logic_module(operand0, operand1, opcode, Arith_result);
`define ALU_width 8;
`define AND 2’d0;`define OR 2’d1;`define XOR 2’d2;`define NOT 2’d3;
input [`ALU_width-1:0] operand0, operand1;output [`ALU_width-1:0] Arith_result; reg [`ALU_width-1:0] Arith_result;input [1:0] opcode;wire [`ALU_width-1:0] zero = 8’b0;
always @(operand0 or operand1 or opcode)case(opcode) `AND : Arith_result = operand1 & operand0; `OR : Arith_result = operand1 | operand0; `XOR : Arith_result = operand0 ^ operand1; `NOT : Arith_result = ~operand0;
endcase
endmodule;
![Page 73: 1 Struttura generale del decoder Tipicamente n input, m=2 n outputs 2-to-4, 3-to-8, 4-to-16, etc. Decoder Circuito che converte un codice di input a nbit](https://reader036.vdocuments.pub/reader036/viewer/2022062512/5542eb57497959361e8c1505/html5/thumbnails/73.jpg)
73
module ALU(operand0, operand1, opcode, ALU_result);
`define ALU_width 8;
input [`ALU_width :0] operand0, operand1;input [2:0] opcode;
…
endmodule;
Input: operand0[7:0], operand1[7:0], opcode[2:0]
Modulo ALU
output: ALU_result[7:0]
module ALU(operand0, operand1, opcode, ALU_result);
`define ALU_width 8;
input [`ALU_width :0] operand0, operand1;input [2:0] opcode;output [`ALU_width :0] ALU_result;
…
endmodule;Unità aritmetica
module ALU(operand0, operand1, opcode, ALU_result);
`define ALU_width 8;
input [`ALU_width :0] operand0, operand1;input [2:0] opcode;output [`ALU_width :0] ALU_result;
wire [`ALU_width :0] Arith_result;Arith_module myArith_module(operand0, operand1, opcode[1:0], Arith_result);
endmodule;
Unità logica
module ALU(operand0, operand1, opcode, ALU_result);
`define ALU_width 8;
input [`ALU_width :0] operand0, operand1;input [2:0] opcode;output [`ALU_width :0] ALU_result;
wire [`ALU_width :0] Arith_result;Arith_module myArith_module(operand0, operand1, opcode[1:0], Arith_result);
wire [`ALU_width :0] Logic_result;Logic_module myLogic_module(operand0, operand1, opcode[1:0], Logic_result);
endmodule;
Mux
module ALU(operand0, operand1, opcode, ALU_result);
`define ALU_width 8;
input [`ALU_width :0] operand0, operand1;input [2:0] opcode;output [`ALU_width :0] ALU_result;
wire [`ALU_width :0] Arith_result;Arith_module myArith_module(operand0, operand1, opcode[1:0], Arith_result);
wire [`ALU_width :0] Logic_result;Logic_module myLogic_module(operand0, operand1, opcode[1:0], Logic_result);Mux myMux(Arith_result,Logic_result,opcode[2], ALU_result);
endmodule;