|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
- `timescale 1ns / 1ps
- `include "D:/Verilog_work/add/Adder_21bits.v"
- module add(
- //input
- ina,inb,inc,
- //output
- oc,result,choosea,chooseb
- );
- input [20:0] ina,inb;
- input inc ;
- output oc;
- output [20:0] result,choosea,chooseb;
- reg [20:0] result;
- reg in_cin = 0 ;
- reg [20:0]choosea,chooseb;
- wire[20:0]chooseresult;
- Adder_21bits add1(.in_a_21bits(choosea),.in_b_21bits(chooseb),
- .sum_21bits(chooseresult),.cin(in_cin),.cout(oc));
- always @(ina,inb,inc)
- begin
- if(ina[20] ==0)
- begin
- choosea = ina;
- end
- else
- begin
- choosea = {ina[20],~ina[19:0]+1};
- end
- if(inb[20] ==0)
- begin
- chooseb = inb;
- end
- else
- begin
- chooseb = {inb[20],~inb[19:0]+1};
- end
- if(chooseresult[20] ==0)
- begin
- result = chooseresult;
- end
- else
- begin
- result = {chooseresult[20],~chooseresult[19:0]+1};
- end
- end
- endmodule
复制代码
为啥我直接给choosea,chooseb 赋值的时候可以得到正确的结果,这么写就不能了,加法器是正确的已经验证过 |
|