You are on page 1of 5

Parte 1 codificador

module CODIFICADOR (

input [3:0] r,

output reg [2:0] o);

always @ (*)

begin

case (r)

4'b1000, 4'b1001, 4'b1010, 4'b1011, 4'b1100, 4'b1101, 4'b1110, 4'b1111: o = 3'b100;

4'b0100, 4'b0101, 4'b0110, 4'b0111: o = 3'b011;

4'b0010, 4'b0011: o = 3'b010;

4'b0001: o = 3'b001;

4'b0000: o = 3'b000;

endcase

end

endmodule
Parte 2 restador
module RESTADOR
#(parameter N=2)
(
input wire [N1:0] a, b,
output wire [N:0] rest
);
localparam N1 = N-2;
assign rest = (a - b);
endmodule
module RESTADOR2 (
input wire [3:0] A, B,
input wire [5:0] C, D, E,
output wire [3:0] x,
output wire [5:0] y, z
);
RESTADOR #(.N(4)) rest1
(.a(A), .b(B), .rest(x));
RESTADOR #(.N(4)) rest2
(.a(C), .b(D), .rest (y));
RESTADOR #(.N(4)) rest3
(.a(y), .b(E), .rest(z));
Endmodule
Parte 3 multiplexor
module MULTIPLEXOR (
input [3:0] D1, D2, D3, D4,
input [1:0] s,
output reg [3:0] y);
always @ (*)
begin
case (s)
2'b00 : y = D1;
2'b01 : y = D2;
2'b10 : y = D3;
2'b11 : y = D4;
endcase
end
endmodule

You might also like