Docsity

Structural Verilog - Digital Design and Synthesis - Solved Assignment, Exercises of Computer Science

Partial preview of the text

Download Structural Verilog - Digital Design and Synthesis - Solved Assignment and more Exercises Computer Science in PDF only on Docsity!

Problem 1:

Truthtable:

Binary Decimal

A B A B AeqB AltB AgtB

module t_leading_zero_detector;

reg [8:0] A; wire [7:0] Astim; wire [2:0] count;

assign Astim=A[7:0];

leading_zero_detector DUT(.count(count),.A(Astim));

initial $monitor("%t A:%b count:%d",$time,Astim,count);

initial begin

for(A=0;A<=8'hff;A=A+1) begin #10; end

#10 $stop; end

endmodule

Problem 3:

a) 1’b

b) 7’b000_

c) 4’b

d) 8’b1010_

e) 16 ’1010_1011_0101_

f) 6’b10_

g) 1’b

h) 1’b

i) 5’b0_

j) 12 ’b0101_0101_

Problem 4:

`default_nettype none

module ALU (output wire [3:0] Y, output wire cout, overflow, zero, input wire [3:0] A, B, input wire cin, input wire [1:0] op);

wire [4:0] negB; wire [4:0] negA;

assign negB = -({B[3],B}); assign negA = -({A[3],A});

assign zero = (Y==4'd0);

assign {cout,Y} = (op==2'b00)? A+B+cin : (op==2'b01)? A+negB[3:0] : (op==2'b10)? A^B: (op==2'b11)? negA[3:0] : 5'bx;

assign overflow = (op==2'b00)? ((cout+A[3]+B[3])!=Y[3]) : (op==2'b01)? ((cout+A[3]+negB[4])!=Y[3]) : (op==2'b10)? 1'bx : (op==2'b11)? (negA[4]!=Y[3]) : 1'bx;

endmodule

module t_ALU; reg signed [3:0] A; reg signed [3:0] B; reg cin; reg [1:0] op;

wire signed [3:0] Y; wire cout, overflow, zero;

ALU DUT(.Y(Y), .cout(cout), .overflow(overflow), .zero(zero),.A(A), .B(B), .cin(cin), .op(op));

initial $monitor("%t, Y:%d, cout:%b, overflow:%b, zero:%b, A:%d,B:%d, cin:%b, op:%b",$time,Y,cout,overflow,zero,A,B,cin,op);

initial begin #10 A=4'd0; B=4'd0; cin=1'b0; op=2'b00; #10 A=4'd2; B=4'd3; cin=1'b0; op=2'b00; #10 A=4'd4; B=4'd2; cin=1'b1; op=2'b00; #10 A=-4'd3; B=4'd5; cin=1'b0; op=2'b00; #10 A=-4'd7; B=4'd8; cin=1'b1; op=2'b00; #10 A=4'd4; B=4'd5; cin=1'b0; op=2'b00; #10 A=-4'd8; B=-4'd8; cin=1'b0; op=2'b00; #10 A=4'd0; B=-4'd8; cin=1'bx; op=2'b01; #10 A=4'd5; B=4'd4; cin=1'bx; op=2'b01; #10 A=-4'd8; B=-4'd8; cin=1'bx; op=2'b01; #10 A=4'd0; B=4'd0; cin=1'bx; op=2'b01; #10 A=-4'd8; B=4'd5; cin=1'bx; op=2'b01; #10 A=4'b1101; B=4'b0110; cin=1'bx; op=2'b10;