当前位置: 首页 > news >正文

Verilog刷题笔记55

题目:
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.
在这里插入图片描述
解题:

module top_module (input clk,input areset,input x,output z
); parameter s0=0,s1=1,s2=2,s3=3;reg [1:0]state,next_state;always@(posedge clk or posedge areset)beginif(areset)state=s0;else state=next_state;endalways@(*)begincase(state)s0:next_state=x?s1:s0;s1:next_state=x?s2:s3;s2:next_state=x?s2:s3;s3:next_state=x?s2:s3;endcaseendalways@(*)begincase(state)s0:z=0;s1:z=1;s2:z=0;s3:z=1;endcaseendendmodule

结果正确:
在这里插入图片描述

知识点:
负数补码规则,负数原码最高位(符号位)不变,其余位取反得到反码,反码加 1 得到补码。
通过观察,本题原码转换为补码有这样一个简单规律:从最低位开始一直到遇到的第一个 1 (例如 100)保持不变(仍为 100),之后一律按位取反。


http://www.mrgr.cn/news/4093.html

相关文章:

  • Ubuntu清除缓存的方法--防止系统崩溃
  • 麻将手游开发的未来之路:技术与创新并行
  • TOMCAT入门到精通
  • Simple RPC - 04 从零开始设计一个客户端(上)
  • 多重示例详细说明Eureka原理实践
  • mockjs的使用
  • python:拆包
  • Nginx服务优化的12个指南:提升性能与稳定性
  • 架构师篇-20、工作坊实战业务架构
  • Redis事务
  • 虚幻引擎游戏开发 | 程序化生成道具位置 Randomize Height
  • 工作纪实56-ES搜索串一致性
  • Python数据结构:集合详解(创建、集合操作)④
  • 基于深度学习的环境感知系统
  • CSS的:required和:optional伪类:提升表单可访问性与用户体验
  • Java实现STL中的全排列函数next_permutation()
  • Frida 的使用
  • 9、Flink SQL 流式概念之状态管理详解
  • 力扣第六十一题——旋转链表
  • 计算机网络12——IM聊天系统——项目分析和架构搭建