这几道题都比较简单,都是看图写代码,快速过一遍
Q143 Exams/2014 q3bfsm
题目链接:Exams/2014 q3bfsm - HDLBits (01xz.net)
代码如下:
module top_module (
input clk,
input reset, // Synchronous reset
input x,
output z
);
parameter A = 3'b000;
parameter B = 3'b001;
parameter C = 3'b010;
parameter D = 3'b011;
parameter E = 3'b100;
reg [2:0] curr_state;
reg [2:0] next_state;
always @(posedge clk) begin
if(reset) begin
curr_state <= A;
end
else begin
curr_state <= next_state;
end
end
always @(*) begin
case(curr_state)
A:next_state = x ? B : A;
B:next_state = x ? E : B;
C:next_state = x ? B : C;
D:next_state = x ? C : B;
E:next_state = x ? E : D;
default: next_state = A;
endcase
end
assign z = (curr_state == D)||(curr_state == E);
endmodule
Q144 Exams/2014 q3c
题目链接:Exams/2014 q3c - HDLBits (01xz.net)
代码如下:
module top_module (
input clk,
input [2:0] y,
input x,
output Y0,
output z
);
always @(*) begin
case(y)
3'b000: Y0 = x;
3'b001: Y0 = ~x;
3'b010: Y0 = x;
3'b011: Y0 = ~x;
3'b100: Y0 = ~x;
default: Y0 = 1'b0;
endcase
end
assign z = (y == 3'b011)||(y == 3'b100);
endmodule
Q145 Exams/m2014 q6b
题目链接:Exams/m2014 q6b - HDLBits (01xz.net)
代码如下:
module top_module (
input [3:1] y,
input w,
output Y2);
always @(*) begin
case(y)
3'b000: Y2 = 1'b0;
3'b001: Y2 = 1'b1;
3'b010: Y2 = w;
3'b011: Y2 = 1'b0;
3'b100: Y2 = w;
3'b101: Y2 = 1'b1;
default: Y2 = 1'b0;
endcase
end
endmodule