Verilog刷题HDLBits——Exams/ece241 2014 q5a

Verilog刷题HDLBits——Exams/ece241 2014 q5a

题目描述

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.

For example:
在这里插入图片描述

代码

module top_module (
    input clk,
    input areset,
    input x,
    output z
); 
    
    parameter idle=0,b1=1,b2=2;
    reg[1:0] state,next_state;
    
    always@(*)
        case(state)
            idle: next_state=x?b1:idle;
            b1:	  next_state=x?b2:b1;
            b2:	  next_state=x?b2:b1;
        endcase
    
    always@(posedge clk or posedge areset)
        if(areset)
            state<=idle;
    	else
            state<=next_state;
    
    assign z = state==b1;

endmodule

结果

在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值