|
`timescale 1ns/1ns
module testbench;
reg clk, rst_n;
initial begin
clk=0;
rst_n=0;
#53 rst_n=1;
end
always #2 clk=~clk;
reg signed [3:0]dx;
reg signed [3:0]dy;
always @(posedge clk or negedge rst_n)
if(~rst_n)begin
dx<=4'd0;
dy<=4'd0;end
else begin
dx<=$random%4;
dy<=$random%4;end
//转换移码
wire [3:0]dx1,dy1;
assign dx1={(~dx[3]),dx[2:0]};
assign dy1={(~dy[3]),dy[2:0]};
wire [3:0]add,sub;
assign add=dx1+dy;
assign sub=dx1-dy;
wire [3:0]add1,sub1;
assign add1={(~add[3]),add[2:0]};
assign sub1={(~sub[3]),sub[2:0]};
endmodule |
|