「HDLBits题解」Building Larger Circuits

2024-01-31 06:12

本文主要是介绍「HDLBits题解」Building Larger Circuits,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

本专栏的目的是分享可以通过HDLBits仿真的Verilog代码 以提供参考 各位可同时参考我的代码和官方题解代码 或许会有所收益


题目链接:Exams/review2015 count1k - HDLBits

module top_module (input clk,input reset,output [9:0] q
);always @(posedge clk) beginif (reset) q <= 0 ; else q <= q == 999 ? 0 : q + 1 ; endendmodule

题目链接:Exams/review2015 shiftcount - HDLBits

module top_module (input clk,input shift_ena,input count_ena,input data,output [3:0] q
);always @(posedge clk) beginif (shift_ena) q <= {q[2:0], data} ; else if (count_ena) q <= q - 1 ; else q <= q ; endendmodule

题目链接:Exams/review2015 fsmseq - HDLBits

module top_module (input clk,input reset,      // Synchronous resetinput data,output start_shifting
);parameter idle = 0, S1 = 1, S2 = 2, S3 = 3, S4 = 4 ; reg [2:0] state, nstate ; always @(*) begincase (state)idle : nstate = data ? S1 : idle ; S1 : nstate = data ? S2 : idle ; S2 : nstate = data ? S2 : S3 ; S3 : nstate = data ? S4 : idle ; S4 : nstate = S4 ;endcaseendalways @(posedge clk) beginif (reset) state <= idle ; else state <= nstate ; endassign start_shifting = state == S4 ;endmodule

题目链接:Exams/review2015 fsmshift - HDLBits

​
module top_module (input clk,input reset,      // Synchronous resetinput data,output start_shifting
);parameter idle = 0, S1 = 1, S2 = 2, S3 = 3, S4 = 4 ; reg [2:0] state, nstate ; always @(*) begincase (state)idle : nstate = data ? S1 : idle ; S1 : nstate = data ? S2 : idle ; S2 : nstate = data ? S2 : S3 ; S3 : nstate = data ? S4 : idle ; S4 : nstate = S4 ;endcaseendalways @(posedge clk) beginif (reset) state <= idle ; else state <= nstate ; endassign start_shifting = state == S4 ;endmodule​

题目链接:Exams/review2015 fsm - HDLBits

module top_module (input clk,input reset,      // Synchronous resetinput data,output shift_ena,output counting,input done_counting,output done,input ack 
);parameter S = 0, S1 = 1, S11 = 2, S110 = 3, B0 = 4, B1 = 5, B2 = 6, B3 = 7, Count = 8, Wait = 9 ; reg [3:0] nstate, state ; always @ (posedge clk) begin if (reset) state <= S ; else state <= nstate ; endalways @ (*) begin case (state) S : nstate = data ? S1 : S ;S1 : nstate = data ? S11 : S ; S11 : nstate = data ? S11 : S110 ; S110 : nstate = data ? B0 : S ; B0 : nstate = B1 ; B1 : nstate = B2 ; B2 : nstate = B3 ; B3 : nstate = Count ; Count : nstate = done_counting ? Wait : Count ; Wait : nstate = ack ? S : Wait ; endcaseendassign shift_ena = (state == B0 | state == B1 | state == B2 | state == B3) ; assign counting = (state == Count) ; assign done = (state == Wait) ;endmodule

题目链接:Exams/review2015 fancytimer - HDLBits

module top_module (input clk,input reset,      // Synchronous resetinput data,input ack, output counting,output done,output [3:0] count 
);parameter S = 0, S1 = 1, S11 = 2, S110 = 3, B0 = 4, B1 = 5, B2 = 6, B3 = 7, Count = 8, Wait = 9 ; reg [3:0] nstate, state ; reg [9:0] cnt ; always @ (posedge clk) begin if (reset) state <= S ; else state <= nstate ; endalways @ (*) begin case (state) S : nstate = data ? S1 : S ;S1 : nstate = data ? S11 : S ; S11 : nstate = data ? S11 : S110 ; S110 : nstate = data ? B0 : S ; B0 : nstate = B1 ; B1 : nstate = B2 ; B2 : nstate = B3 ; B3 : nstate = Count ; Count : nstate = (count == 0 & cnt == 999) ? Wait : Count ; Wait : nstate = ack ? S : Wait ; endcaseendalways @ (posedge clk) begin case (state) B0 : count[3] <= data ; B1 : count[2] <= data ; B2 : count[1] <= data ; B3 : count[0] <= data ; Count : begin if (count >= 0) if (cnt < 999) cnt <= cnt + 1 ; else begin count <= count - 1 ; cnt <= 0 ; endenddefault : cnt <= 0 ; endcaseendassign counting = (state == Count) ; assign done = (state == Wait) ; endmodule

题目链接:Exams/review2015 fsmonehot - HDLBits

module top_module(input d,input done_counting,input ack,input [9:0] state,    // 10-bit one-hot current stateoutput B3_next,output S_next,output S1_next,output Count_next,output Wait_next,output done,output counting,output shift_ena
); //// You may use these parameters to access state bits using e.g., state[B2] instead of state[6].parameter S=0, S1=1, S11=2, S110=3, B0=4, B1=5, B2=6, B3=7, Count=8, Wait=9;assign B3_next = state[B2];assign S_next = (state[S] & (~d)) | (state[S1] & (~d)) | (state[S110] & (~d)) | (state[Wait] & ack);assign S1_next = state[S] & d;assign Count_next = state[B3] | (state[Count] & (~done_counting));assign Wait_next = (state[Count] & (done_counting)) | (state[Wait] & (~ack));assign done = state[Wait];assign counting = state[Count];assign shift_ena = state[B0] | state[B1] | state[B2] | state[B3];endmodule

这篇关于「HDLBits题解」Building Larger Circuits的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/662802

相关文章

C++ | Leetcode C++题解之第393题UTF-8编码验证

题目: 题解: class Solution {public:static const int MASK1 = 1 << 7;static const int MASK2 = (1 << 7) + (1 << 6);bool isValid(int num) {return (num & MASK2) == MASK1;}int getBytes(int num) {if ((num &

C语言 | Leetcode C语言题解之第393题UTF-8编码验证

题目: 题解: static const int MASK1 = 1 << 7;static const int MASK2 = (1 << 7) + (1 << 6);bool isValid(int num) {return (num & MASK2) == MASK1;}int getBytes(int num) {if ((num & MASK1) == 0) {return

C - Word Ladder题解

C - Word Ladder 题解 解题思路: 先输入两个字符串S 和t 然后在S和T中寻找有多少个字符不同的个数(也就是需要变换多少次) 开始替换时: tips: 字符串下标以0开始 我们定义两个变量a和b,用于记录当前遍历到的字符 首先是判断:如果这时a已经==b了,那么就跳过,不用管; 如果a大于b的话:那么我们就让s中的第i项替换成b,接着就直接输出S就行了。 这样

【秋招笔试】9.07米哈游秋招改编题-三语言题解

🍭 大家好这里是 春秋招笔试突围,一起备战大厂笔试 💻 ACM金牌团队🏅️ | 多次AK大厂笔试 | 大厂实习经历 ✨ 本系列打算持续跟新 春秋招笔试题 👏 感谢大家的订阅➕ 和 喜欢💗 和 手里的小花花🌸 ✨ 笔试合集传送们 -> 🧷春秋招笔试合集 🍒 本专栏已收集 100+ 套笔试题,笔试真题 会在第一时间跟新 🍄 题面描述等均已改编,如果和你笔试题看到的题面描述

LeetCode 第414场周赛个人题解

目录 Q1. 将日期转换为二进制表示 原题链接 思路分析 AC代码 Q2. 范围内整数的最大得分 原题链接 思路分析 AC代码 Q3. 到达数组末尾的最大得分 原题链接 思路分析 AC代码 Q4. 吃掉所有兵需要的最多移动次数 原题链接 思路分析 AC代码 Q1. 将日期转换为二进制表示 原题链接 Q1. 将日期转换为二进制表示 思路分析

牛客小白月赛100部分题解

比赛地址:牛客小白月赛100_ACM/NOI/CSP/CCPC/ICPC算法编程高难度练习赛_牛客竞赛OJ A.ACM中的A题 #include<bits/stdc++.h>using namespace std;#define ll long long#define ull = unsigned long longvoid solve() {ll a,b,c;cin>>a>>b>

P2858 [USACO06FEB] Treats for the Cows G/S 题解

P2858 题意 给一个数组。每天把最左或者最右的东西卖掉,第 i i i个东西,第 d a y day day天卖出的价格是 a [ i ] ∗ d a y a[i]*day a[i]∗day。 记忆化搜索 void dfs(int l,int r,int day,ll sum){if(v[l][r]>=sum)return;v[l][r]=sum;if(l>r)//这就是dp答案{

【C++题解】1272. 郭远摘苹果

欢迎关注本专栏《C++从零基础到信奥赛入门级(CSP-J)》 问题:1272. 郭远摘苹果 类型:二维数组 题目描述: 郭远有一天走到了一片苹果林,里面每颗树上都结有不同数目的苹果,郭远身上只能拿同一棵树上的苹果,他每到一棵果树前都会把自己身上的苹果扔掉并摘下他所在树上的苹果并带走(假设郭远会走过每一棵苹果树),问在郭远摘苹果的整个过程中,他身上携带的最多苹果数与最小苹果数的差是多少?

【最新华为OD机试E卷-支持在线评测】机器人活动区域(100分)多语言题解-(Python/C/JavaScript/Java/Cpp)

🍭 大家好这里是春秋招笔试突围 ,一枚热爱算法的程序员 ✨ 本系列打算持续跟新华为OD-E/D卷的三语言AC题解 💻 ACM金牌🏅️团队| 多次AK大厂笔试 | 编程一对一辅导 👏 感谢大家的订阅➕ 和 喜欢💗 🍿 最新华为OD机试D卷目录,全、新、准,题目覆盖率达 95% 以上,支持题目在线评测,专栏文章质量平均 94 分 最新华为OD机试目录: https://blog.

2023 CCPC(秦皇岛)现场(第二届环球杯.第 2 阶段:秦皇岛)部分题解

所有题目链接:Dashboard - The 2023 CCPC (Qinhuangdao) Onsite (The 2nd Universal Cup. Stage 9: Qinhuangdao) - Codeforces 中文题面: contest-37054-zh.pdf (codeforces.com) G. Path 链接: Problem - G - Codeforces