Verilog 程序理解问题 关于状态机
时间:10-02
整理:3721RD
点击:
程序是用状态机实现16位编码module multiplication(mux,pmux,reset,clk,out,mid,done);
input [15:0]mux,pmux;
input clk,reset;
output [31:0]out,mid;
output done;
reg [31:0]out,mid;
reg done;
integer count;
reg [1:0]pstate,nstate;
parameter idle=2'b00,add=2'b01,shift=2'b10;
always@(posedge clk)
if(!reset) begin
pstate=idle;
end
else begin
pstate = nstate;
end
always@(pstate)
begin
case(pstate)
idle:
begin
out=0;
done=0;
count=0;
mid[15:0]=mux;
mid[31:16]=16'b0;
nstate=add;
end
add:
begin
if(pmux[count])
out=out+mid;
nstate=shift;////////////这里
end
shift:
begin
count=count+1;
mid={mid[30:0],1'b0};
if(count==16)
begin
nstate=idle;
done=1;
end
else
nstate=add;
end
default:
nstate=idle;
endcase
end
endmodule
想请教一下,当红色if语句不满足时,状态是否转移?程序怎么继续下去
input [15:0]mux,pmux;
input clk,reset;
output [31:0]out,mid;
output done;
reg [31:0]out,mid;
reg done;
integer count;
reg [1:0]pstate,nstate;
parameter idle=2'b00,add=2'b01,shift=2'b10;
always@(posedge clk)
if(!reset) begin
pstate=idle;
end
else begin
pstate = nstate;
end
always@(pstate)
begin
case(pstate)
idle:
begin
out=0;
done=0;
count=0;
mid[15:0]=mux;
mid[31:16]=16'b0;
nstate=add;
end
add:
begin
if(pmux[count])
out=out+mid;
nstate=shift;////////////这里
end
shift:
begin
count=count+1;
mid={mid[30:0],1'b0};
if(count==16)
begin
nstate=idle;
done=1;
end
else
nstate=add;
end
default:
nstate=idle;
endcase
end
endmodule
想请教一下,当红色if语句不满足时,状态是否转移?程序怎么继续下去
你这个if下面没有begin end,只能作用一条语句,无路如何都会跳转啊
懂了,谢谢