// zad 4 z instrukcji
// 1 sposob
module funkcja (a, b, c, d, Z);
imput a, b, c, d;
output Z;
reg Z;
always @(Z or a or b or c or d)
Z = ~(~(c & d) & ~(b & c) & ~(b & ~d & ~a));
//2 sposob
module funkcja (a, b, c, d, Z);
imput a, b, c, d;
output Z;
assign Z = ~(~(c & d) & ~(b & c) & ~(b & ~d & ~a));
// u Czyza
// Zad1
// a) Sumator 1-bitowy
module sum1 (a, b, Cin, Cout, S);
input a, b, Cin;
output S, Cout;
assign S = ((a ^ b) ^ Cin);
assign Cout = ((Cin & (a ^ b)) | (a & b));
endmodule
// 2 sumatory
module sum2 (
input [1:0]a,
input [1:0]b,
input Cin,
output [2:0] y
);
wire carry0;
sumator sum1 (a[0], b[0], Cin, y[0], carry0);
sumator sum2 (a[1], b[1], y[1], y[2], carry0);
endmodule
// 3 sumatory
module sum3 (
input [2:0]a,
input [2:0]b,
input Cin,
output [3:0] y
);
wire carry0,carry1;
sum1 sumator1 (a[0], b[0], Cin, y[0], carry0);
sum1 sumator2 (a[1], b[1], carry0, y[1], carry1);
sum1 sumator3 (a[2], b[2], carry1, y[2], y[3]);
endmodule
// b) polaczenie 2 sumatorow
// module sum2 (a0, b0, a1, b1, Cin, Cout1, Cout2, S1, S0);
// input a0, b0, a1, b1, Cin;
// output S0, S1, Cout1, Cout2;
// assign S0 = ((a0 ^ b0) ^ Cin);
// assign Cout1 = ((Cin & (a0 ^ b0)) | (a0 & b0));
// assign S1 = (Cout1 ^ (a1 ^ b1));
// assign Cout2 = (((a1 ^ b1) & Cout1) | (a1 & b1));
// u Mazura
// Zad 1
module nand (a, b, y);
input a, b;
output y;
assign y = (a & b);
// Zad 2
module konwerter (g0, g1, g2, a, b, c);
input g0, g1, g2;
output a, b, c;
assign a = g0;
assign b = (g0 ^ g1);
assign c = (g0 ^ g1 ^ g2);
// Licznik jedynek
module licznik (a, b, c, d, e, f, g, h, w, x, y, z);
imput a, b, c, d, e, f, g, h;
output w, x, y, z;
reg w,x,y,z;
always @(a or b or c or d or e or f or g or h or w or x or y or z)
out = 1;
case ( a || b || c || d || e || f || g || h == 1'b1 )
out = z;
endcase
case ( a && b && c && d && e && f && g && h == 1'b1 )
out = w;
out = x;
out = y;
out = z;
endcase
case ( a && b || a && c || a && d || a && e || a && f || b && c || b && d || b && e || b && f || c && d || c && e ||c && f || d && e || d && f || e && f == 1'b1 ) begin
out =y;
endcase
endmodule
module licz0(x1,x2,x3,x4,x5,x6,x7,x8,y0,y1,y2,y3);
input x1,x2,x3,x4,x5,x6,x7,x8;
output y0,y1,y2,y3;
reg y0,y1,y2,y3;
integer jedynki,zera;
always @(x1 or x2 or x3 or x4 or x5 or x6 or x7 or x8) begin
jedynki = x1+x2+x3+x4+x5+x6+x7+x8;
zera = 8 - jedynki;
y0=0;
y1=0;
y2=0;
y3=0;
if(zera==0) begin
end else if(zera==1) begin
y0=1;
end else if(zera==2) begin
y1=1;
end else if(zera==3) begin
y0=1;
y1=1;
end else if(zera==4) begin
y2=1;
end else if(zera==5) begin
y0=1;
y2=1;
end else if(zera==6) begin
y1=1;
y2=1;
end else if(zera==7) begin
y0=1;
y1=1;
y2=1;
end else if(zera==8) begin
y3=1;
end
end
endmodule