yvhksovo 发表于 2010-8-5 17:00:18

夏宇闻书上的一道练习题.

夏宇闻书上的一道练习题:
假设有4个8位数据是按照时钟节拍串行输入的,
要求用时钟触发任务,
每个时钟周期完成一次数据的冒泡排序。
module(
                input a,
                input b,
                input c,
                input d,
                input clk,
                output reg a1,
                output reg a2,
                output reg a3,
                output reg a4
        );

我估计是要考察流水线.但是我想了很久也没想到好的办法.
大家有谁做过这个练习么.

wso75839840 发表于 2010-8-7 21:34:27

新手飘过,等待高手来解答。
不知道流水线是怎么用。
能不能象C语文那样用forever?

gliet_su 发表于 2010-8-7 23:16:44

首先嵌一个51核,余下的就好搞定了

honsimark 发表于 2010-8-12 20:42:53

这个不难,我做过流水线实现冒泡法的设计,可以先用4个dff串连,
组成移位寄存器,引出4个抽头,然后接到比较器中,比较器采用寄存器输出
http://cache.amobbs.com/bbs_upload782111/files_32/ourdev_574640.png
这是原理图,由四级流水线实现,每级比较一次,实现一次移动,总共四级饥渴完成 (原文件名:冒泡法排序流水线实现原理图.png)

yvhksovo 发表于 2010-8-16 15:49:49

回复【3楼】honsimark
-----------------------------------------------------------------------

嗯,好方法....谢谢

yvhksovo 发表于 2010-8-21 11:43:31

回复【3楼】honsimark
-----------------------------------------------------------------------

看来是我的理解有问题.

流水线排序
module cmp(
                        input clk,
                        input rst,
                        input data,
                        output reg data1,
                        output reg data2,
                        output reg data3,
                        output reg data4
                );
reg temp1,temp2,temp3,temp4;
always @ (posedge clk)
        if(!rst)
                begin
                        temp1<=8'd0;
                        temp2<=8'd0;
                        temp3<=8'd0;
                        temp4<=8'd0;
                end
        else
                begin
                        temp1<=data;
                        temp2<=temp1;
                        temp3<=temp2;
                        temp4<=temp3;
                end
reg t1,t2,t3,t4;
always @ (posedge clk)
begin
        sort(temp1,temp2,t1,t2);
        sort(temp3,temp4,t3,t4);
end

reg t21,t22,t23,t24;
always @ (posedge clk)
begin
        t21<=t1;
        sort(t2,t3,t22,t23);
        t24<=t4;
end

reg t31,t32,t33,t34;
always @ (posedge clk)
        begin
                sort(t21,t22,t31,t32);
                sort(t23,t24,t33,t34);
        end

always @ (posedge clk)
        begin
                data1<=t31;
                sort(t32,t33,data2,data3);
                data4<=t34;
        end
/*********交换位置的任务***************/
task sort;
        input ix,iy;
        output ox,oy;
        if(ix<iy)
                begin
                        ox<=iy;
                        oy<=ix;
                end
        else
                begin
                        ox<=ix;
                        oy<=iy;
                end
endtask
                       
endmodule


组合逻辑排序

module sort4(ra,rb,rc,rd,a,b,c,d);
input a,b,c,d;
output ra,rb,rc,rd;
reg ra,rb,rc,rd;
reg va,vb,vc,vd;
always @ (a or b or c or d)
        begin
                {va,vb,vc,vd}={a,b,c,d};
                sort(va,vc);
                sort(vb,vd);
               
                sort(va,vb);
                sort(vc,vd);
               
                sort(vb,vc);
                {ra,rb,rc,rd}={va,vb,vc,vd};
        end

task sort;
        inout x,y;
        reg temp;
        if(x>y)
                begin
                        temp=x;
                        x=y;
                        y=temp;
                end
        else
                temp=4'd0;
endtask
endmodule


哪种排序方法更优越?为什么?

honsimark 发表于 2010-8-21 17:24:26

组合逻辑可定是不行的,要求是按照时钟节拍串行输入的,再说组合逻辑可能不太稳定,上面的时序逻辑对的,不错!,和上面的原理图一个意思
页: [1]
查看完整版本: 夏宇闻书上的一道练习题.