Professional Documents
Culture Documents
Verilog Present 2
Verilog Present 2
Outline
Half Adder and Testbench 4-to-1 Multiplexor 2-to-4 Decoder ALU Register File CPU
4-to-1 Multiplexor
Sel In1 In2 In3 In4
MUX
Out
Decoder
en
Y3
Decoder
B
Y2 Y1 Y0
Decoder
module decoder 2 to 4 (Y3, Y2, Y1, Y0, A, B, en); output Y3, Y2, Y1, Y0; input A, B; input en; reg Y3, Y2, Y1, Y0;
always @(A or B or en) begin if (en == 1) case ( {A,B} ) 2'b00: {Y3,Y2,Y1,Y0} = 4'b1110; 2'b01: {Y3,Y2,Y1,Y0} = 4'b1101; 2'b10: {Y3,Y2,Y1,Y0} = 4'b1011; 2'b11: {Y3,Y2,Y1,Y0} = 4'b0111; default: {Y3,Y2,Y1,Y0} = 4'bxxxx; endcase
A Register File
A register file consists of a set of registers that can be read and written by supplying a register number to be accessed. The read ports cab be implemented with a pair of multiplexors. The write port can be implemented with a decoder
The implementation of two read ports for a register file with n registers can be done with a pair of n-to-1 multiplexors each 32 bits wide.
The write port for a register file is implemented with a decoder that is used with the write signal to generate the C input to the registers.