源码:
module YWJCQ(
input clk,
input rst_n,
input [2:0]sel,
input [7:0]in,
output out_o
);
reg out;
always@(sel)
begin
case(sel)
3’d0: out<=in[0];
3’d1: out<=in[1];
3’d2: out<=in[2];
3’d3: out<=in[3];
3’d4: out<=in[4];
3’d5: out<=in[5];
3’d6: out<=in[6];
3’d7: out<=in[7];
default:;
endcase
end
assign out_o=out;
endmodule
激励:
`timescale 1ns/1ns
module YWJCQ_tb();
reg clk;
reg rst_n;
reg [7:0]in;
reg [2:0] sel;
initial
begin
rst_n=0;
100 rst_n=1;
#1000 $stop;
end
initial
begin
clk=0;
end
initial
begin
in=8’b01000111;
end
initial
begin
sel=3’b000;
#100 sel=3’b001;
#100 sel=3’b010;
#100 sel=3’b011;
#100 sel=3’b100;
#100 sel=3’b101;
#100 sel=3’b110;
#100 sel=3’b111;
end
always #10 clk<=~clk;
YWJCQ YWJCQ_out(
.clk(clk),
.rst_n(rst_n),
.in(in),
.sel(sel),
.out_o()
);
endmodule
数据抽取最主要的是数据的分离与case语句的用法。
case的格式:
always@(ct)
begin
out=xxxx;
case(ct)
x’bxxxx:out=xxxxx;
…
…
…
endcase
end