HDLBits 系列(34)Serial two's complememter(Mealy and Moore FSM)

举报
李锐博恩 发表于 2021/07/15 03:20:18 2021/07/15
【摘要】 目录 Mealy 状态机 原题复现 我的设计 Moore 状态机 原题复现 状态转移图 我的设计 Mealy 状态机 原题复现 原题复现: The following diagram is a Mealy machine implementation of the 2's complementer. Implement using one-hot...

目录

Mealy 状态机

原题复现

我的设计

Moore 状态机

原题复现

状态转移图

我的设计


Mealy 状态机

原题复现

原题复现:

The following diagram is a Mealy machine implementation of the 2's complementer. Implement using one-hot encoding.

尽管我不太清楚这是个为啥?

但既然状态转移图都给你了,设计一个mealy状态机应该不成问题:

我的设计


  
  1. module top_module (
  2. input clk,
  3. input areset,
  4. input x,
  5. output z
  6. );
  7. localparam A = 2'b01, B = 2'b10;
  8. reg [1:0] state, next_state;
  9. always@(*)begin
  10. case(state)
  11. A: begin
  12. if(x) next_state = B;
  13. else next_state = A;
  14. end
  15. B: begin
  16. next_state = B;
  17. end
  18. default: begin
  19. next_state = A;
  20. end
  21. endcase
  22. end
  23. always@(posedge clk or posedge areset) begin
  24. if(areset) state <= A;
  25. else state <= next_state;
  26. end
  27. assign z = (state == A)?x:~x;
  28. /*
  29. reg z_mid;
  30. always@(*)begin
  31. case(state)
  32. A: begin
  33. if(x) z_mid = 1;
  34. else z_mid = 0;
  35. end
  36. B: begin
  37. if(x) z_mid = 0;
  38. else z_mid = 1;
  39. end
  40. default: begin
  41. z_mid = 0;
  42. end
  43. endcase
  44. end
  45. assign z = z_mid;
  46. */
  47. endmodule

Moore 状态机

姊妹篇,用Moore状态机如何实现?

原题复现

原题复现:

You are to design a one-input one-output serial 2's complementer Moore state machine. The input (x) is a series of bits (one per clock cycle) beginning with the least-significant bit of the number, and the output (Z) is the 2's complement of the input. The machine will accept input numbers of arbitrary length. The circuit requires an asynchronous reset. The conversion begins when Reset is released and stops when Reset is asserted.

状态转移图

我们根据mealy状态机的状态转移图来画Moore状态机的状态转移图,然后完成设计。

我的设计

给出设计:


  
  1. module top_module (
  2. input clk,
  3. input areset,
  4. input x,
  5. output z
  6. );
  7. localparam A = 0, B = 1, C = 2, D = 3;
  8. reg [1:0] state, next_state;
  9. always@(*) begin
  10. case(state)
  11. A: begin
  12. if(x) next_state = B;
  13. else next_state = A;
  14. end
  15. B: begin
  16. if(x) next_state = D;
  17. else next_state = C;
  18. end
  19. C: begin
  20. if(x) next_state = D;
  21. else next_state = C;
  22. end
  23. D: begin
  24. if(x) next_state = D;
  25. else next_state = C;
  26. end
  27. default: begin
  28. next_state = A;
  29. end
  30. endcase
  31. end
  32. always@(posedge clk or posedge areset) begin
  33. if(areset) state <= A;
  34. else state <= next_state;
  35. end
  36. assign z = (state == B || state == C)? 1 : 0;
  37. endmodule

 

 

文章来源: reborn.blog.csdn.net,作者:李锐博恩,版权归原作者所有,如需转载,请联系作者。

原文链接:reborn.blog.csdn.net/article/details/103454958

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。