verilog HDLBits刷题[Finite State Machines]“Fsm onehot”---One-hot FSM

发布时间:2026/9/28 5:37:34
verilog HDLBits刷题[Finite State Machines]“Fsm onehot”---One-hot FSM 1、题目Given the following state machine with 1 input and 2 outputs:Suppose this state machine uses one-hot encoding, where state[0] through state[9] correspond to the states S0 though S9, respectively. The outputs are zero unless otherwise specified.Implement thestate transition logicandoutput logicportions of the state machine (but not the state flip-flops). You are given the current state in state[9:0] and must produce next_state[9:0] and the two outputs. Derive the logic equations by inspection assuming a one-hot encoding. (The testbench will test with non-one hot inputs to make sure youre not trying to do something more complicated).2、分析独热编码只有1bit为1其它全为0。有S0-S9一共10个状态但输入已经有当前状态不需要自定义状态。除了图中标注的特定输出其它输出都为0.3、代码module top_module( input in, input [9:0] state, output [9:0] next_state, // wire不要reg output out1, output out2); assign next_state[0] (state[0]~in) | (state[1]~in) | (state[2]~in) | (state[3]~in) | (state[4]~in) | (state[7]~in) | (state[8]~in) | (state[9]~in); assign next_state[1] (state[0]in) | (state[8]in) | (state[9]in); assign next_state[2] (state[1]in); assign next_state[3] (state[2]in); assign next_state[4] (state[3]in); assign next_state[5] (state[4]in); assign next_state[6] (state[5]in); assign next_state[7] (state[6]in) | (state[7]in); assign next_state[8] (state[5]~in); assign next_state[9] (state[6]~in); assign out1 state[8] || state[9]; assign out2 state[7] || state[9]; endmodule 或者 module top_module( input in, input [9:0] state, output reg [9:0] next_state, output out1, output out2); always (*) begin next_state 10d0; // 初始全部清零避免锁存 if(state[0]) begin next_state[0] ~in; next_state[1] in; end if(state[1]) begin next_state[0] ~in; next_state[2] in; end if(state[2]) begin next_state[0] ~in; next_state[3] in; end if(state[3]) begin next_state[0] ~in; next_state[4] in; end if(state[4]) begin next_state[0] ~in; next_state[5] in; end if(state[5]) begin next_state[8] ~in; next_state[6] in; end if(state[6]) begin next_state[9] ~in; next_state[7] in; end if(state[7]) begin next_state[0] ~in; next_state[7] in; end if(state[8]) begin next_state[0] ~in; next_state[1] in; end if(state[9]) begin next_state[0] ~in; next_state[1] in; end end assign out1 state[8] || state[9]; assign out2 state[7] || state[9]; endmodule4、结果

关于本文作者

来自尧图内容编辑团队

尧图内容编辑团队 内容团队

尧图内容编辑团队

本文由尧图网络内容编辑团队执笔。团队由资深项目经理、前端工程师与设计师组成,所有内容均来自亲手交付的真实项目,先讲清问题、再给出可落地的解法。尧图深耕北京网站建设十年,服务过京华建材集团、智造科技等各行业客户,把一线经验沉淀为可复用的行业观察。

  • 十年建站经验,覆盖建材、制造、服务、文创等
  • 项目经理把关选题与事实准确性
  • 工程师与设计师联合撰写专业细节
  • 统一编辑规范,保证文风与排版一致
  • 每月复盘转化数据,迭代选题方向

延伸阅读

相关资讯与近期热门内容

深度阅读推荐

建站决策前值得细读的三篇

网站改版的5个关键决策
2024-08-12

网站改版的5个关键决策

什么时候该改版、改到什么程度、如何避免流量掉光,京华建材集团改版复盘给出答案。

获取专属建站方案

看完文章,把您的行业与预算告诉我们,免费获取一份量身定制的官网建设方案与报价。

立即免费咨询