FGPA 130实例-->problem 5.1~5.3
2016-06-03 10:44
232 查看
case语句描述4选1数据选择器
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
module mux4_1(out,in0,in1,in2,in3,sel);
output out;
input in0,in1,in2,in3;
input [1:0] sel;
reg out;
always @ (in0 or in1 or in2 or in3 or sel)
case(sel)
2'b00:out<=in0;
2'b01:out<=in1;
2'b10:out<=in2;
2'b11:out<=in3;
default:out<=1'bx;
endcase
endmodule
同步置数,同步清零的计数器
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
module count(out,data,load,reset,clk);
output [7:0] out;
input [7:0] data;
input load,reset,clk;
reg out;
always @ (posedge clk)
begin
if(!reset) out<=8'd0;
else if (load) out<=data;
else out<=out+8'd1;
end
endmodule
用always过程语句描述的简单算术逻辑单元
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
`define add 3'd1
`define minus 3'd2
`define band 3'd3
`define bor 3'd4
`define bnot 3'd5
module alu(out,opcode,a,b);
output [7:0] out;
reg [7:0] out;
input [2:0] opcode;
input [7:0] a,b;
always @ (a or b or opcode)
begin
case(opcode)
`add: out = a+b;
`minus: out=a-b;
`band: out=a&b;
`bor: out=a|b;
`bnot: out=~a;
default:out<=8'hx;
endcase
end
endmodule
遇到的问题:在使用 `define add 3'd1; 分号导致宏变量,引用替换的时候也加入的分号,结果编译出错。
Line 69: Syntax error near ";".
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
module mux4_1(out,in0,in1,in2,in3,sel);
output out;
input in0,in1,in2,in3;
input [1:0] sel;
reg out;
always @ (in0 or in1 or in2 or in3 or sel)
case(sel)
2'b00:out<=in0;
2'b01:out<=in1;
2'b10:out<=in2;
2'b11:out<=in3;
default:out<=1'bx;
endcase
endmodule
同步置数,同步清零的计数器
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
module count(out,data,load,reset,clk);
output [7:0] out;
input [7:0] data;
input load,reset,clk;
reg out;
always @ (posedge clk)
begin
if(!reset) out<=8'd0;
else if (load) out<=data;
else out<=out+8'd1;
end
endmodule
用always过程语句描述的简单算术逻辑单元
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
`define add 3'd1
`define minus 3'd2
`define band 3'd3
`define bor 3'd4
`define bnot 3'd5
module alu(out,opcode,a,b);
output [7:0] out;
reg [7:0] out;
input [2:0] opcode;
input [7:0] a,b;
always @ (a or b or opcode)
begin
case(opcode)
`add: out = a+b;
`minus: out=a-b;
`band: out=a&b;
`bor: out=a|b;
`bnot: out=~a;
default:out<=8'hx;
endcase
end
endmodule
遇到的问题:在使用 `define add 3'd1; 分号导致宏变量,引用替换的时候也加入的分号,结果编译出错。
Line 69: Syntax error near ";".
相关文章推荐
- android HandlerThread的使用
- emacs 常用自定义快捷键设置
- Makefile的基本规则
- 斐波那契数列
- matplotlib核心剖析
- 程序员装逼实用宝典
- Android安全攻防战,反编译与混淆技术完全解析
- 软件工程课程的建议
- 设计模式之组合模式
- Android动态加载轮播图BannerView
- jdbcTemplate增删改查
- 深度学习——Xavier初始化方法
- HA高可用集群/LB负载均衡 添加一张虚拟网卡
- Struts2 深入理解
- "Could not open '/sys/class/power_supply/genymotion_fake_path/present'
- CAS-ERR Cannot create a session after the response has been committed
- Leetcode-234. Palindrome Linked List(判断链表是否回文)
- Android动画机制与使用技巧(四)——Android动画特效
- linux系统c线程池的实现
- shell 脚本之for