编了求最大公约数的代码,刚开始想用组合逻辑电路构造,编了半个小时,搞不出来啊,各种问题,无奈还是引入时钟,嗨。。。。是我太笨了吗?求大神指点啊,为啥有的组合逻辑这么难编呢?有什么好的方法吗?下面是代码,欢迎各位批评指点哈
module gys (clk,rst,a, b, out);
input [4:0] a, b;
input rst,clk;
output [4:0] out;
reg [4:0] out;
reg [4:0] A, B, swap;
reg done;
always @(posedge clk)
begin
if(!rst)
begin
done = 0;
A = a;
B = b;
end
else if( A < B && !done )
begin
swap = A;
A = B;
B = swap;
end
else if (B )
A = A - B;
else
begin
done = 1;
out = A;
end
end
endmodule |