verilog HDLBits刷题[Finite State Machines]“Lemmings4”---Lemmings4 1、题目See also: Lemmings1, Lemmings2, and Lemmings3.Although Lemmings can walk, fall, and dig, Lemmings arent invulnerable. If a Lemming falls for too long then hits the ground, it can splatter. In particular, if a Lemming falls for more than 20 clock cycles then hits the ground, it will splatter and cease walking, falling, or digging (all 4 outputs become 0), forever (Or until the FSM gets reset). There is no upper limit on how far a Lemming can fall before hitting the ground. Lemmings only splatter when hitting the ground; they do not splatter in mid-air.Extend your finite state machine to model this behaviour.Falling for 20 cycles is survivable:2、代码module top_module( input clk, input areset, // Freshly brainwashed Lemmings walk left. input bump_left, input bump_right, input ground, input dig, output walk_left, output walk_right, output aaah, output digging ); localparam LEFT 1, RIGHT 2, FALL_L 3, FALL_R 4, DIG_L 5, DIG_R 6, SPLAT 7; reg [2:0] state; reg [2:0] next_state; reg [6:0] cnt; // watch out this! always (posedge clk , posedge areset)begin if(areset) state LEFT; else state next_state; end always (posedge clk or posedge areset)begin if(areset) cnt 7d0; else if(state FALL_L || state FALL_R) cnt cnt 1b1; else cnt 7d0; end always (*) case(state) LEFT : next_state ~ground ? FALL_L : (dig ? DIG_L : (bump_left ? RIGHT : LEFT)); RIGHT : next_state ~ground ? FALL_R : (dig ? DIG_R : (bump_right ? LEFT : RIGHT)); FALL_L : next_state ground ? (cnt 5d20 ? SPLAT : LEFT) : FALL_L; FALL_R : next_state ground ? (cnt 5d20 ? SPLAT : RIGHT) : FALL_R; DIG_L : next_state ~ground ? FALL_L : DIG_L; DIG_R : next_state ~ground ? FALL_R : DIG_R; SPLAT : next_state SPLAT; endcase assign walk_left (state LEFT); assign walk_right (state RIGHT); assign aaah (state FALL_L) || (state FALL_R); assign digging (state DIG_L) || (state DIG_R); endmodule3、结果

相关新闻

最新新闻

SerenityOS 命令行选项解析指南:getopt 与 getopt_long 用法、返回值与底层实现

SerenityOS 命令行选项解析指南:getopt 与 getopt_long 用法、返回值与底层实现

SerenityOS 命令行选项解析指南:getopt 与 getopt_long 用法、返回值与底层实现 【免费下载链接】serenity The Serenity Operating System 🐞 项目地址: https://gitcode.com/GitHub_Trending/se/serenity 导读 本文以 getopt(3) 手册 为核心&a…

2026/10/1 19:32:24
轻量服务器还是ECS?大促云服务器选购与避坑实战指南

轻量服务器还是ECS?大促云服务器选购与避坑实战指南

每年大促节点,群里永远有人在问同一个问题:“38元的轻量服务器到底怎么抢?为什么我每次点进去都是已售罄?68元直购和99元的ECS我到底选哪个?”作为一个常年帮团队和自己采购云服务器的老用户,我太清楚这种纠…

2026/9/30 21:32:07
为 AI 代理的 Review 动作编写 Cedar 审批门控策略:review-agent-governance 策略编写实战指南

为 AI 代理的 Review 动作编写 Cedar 审批门控策略:review-agent-governance 策略编写实战指南

为 AI 代理的 Review 动作编写 Cedar 审批门控策略:review-agent-governance 策略编写实战指南 【免费下载链接】agents Multi-harness agentic plugin marketplace for Claude Code, Codex, Cursor, OpenCode, GitHub Copilot, and Google Antigravity 项目地址:…

2026/9/30 19:41:56
PaddleOCR 手写数学公式识别算法 CAN 实战指南:Counting-Aware Network 训练、评估与推理部署

PaddleOCR 手写数学公式识别算法 CAN 实战指南:Counting-Aware Network 训练、评估与推理部署

PaddleOCR 手写数学公式识别算法 CAN 实战指南:Counting-Aware Network 训练、评估与推理部署 【免费下载链接】PaddleOCR Turn any PDF or image document into structured data for your AI. A powerful, lightweight OCR toolkit that bridges the gap between i…

2026/10/1 19:32:23
Spring源码解析:构造器注入的类型转换与候选匹配机制

Spring源码解析:构造器注入的类型转换与候选匹配机制

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

2026/10/1 19:32:35
openai-agents-python 多模型接入指南:深入解析 AnyLLMModel 适配层与 any-llm 路由

openai-agents-python 多模型接入指南:深入解析 AnyLLMModel 适配层与 any-llm 路由

openai-agents-python 多模型接入指南:深入解析 AnyLLMModel 适配层与 any-llm 路由 【免费下载链接】openai-agents-python A lightweight, powerful framework for multi-agent workflows 项目地址: https://gitcode.com/GitHub_Trending/op/openai-agents-pyth…

2026/9/30 21:32:11

日新闻

周新闻

月新闻