integer cnt;
initial
begin
in_data = 0;
#(CYC);
for(cnt = 1; cnt <100; cnt = cnt + 1)
begin
in_data = cnt;
#(CYC);
end
for(cnt = 16'h8000; cnt < 16'h8100; cnt = cnt + 1)
begin
in_data = cnt;
#(CYC);
end
$stop;
end
endmodule
/////////////////////////////////////////////////////
注意由于正负的不对称性,在16‘h8000处对应的正数会溢出。
(3)在写入测试数据时,可能会用到要将有符号数转成无符号数表示的情况,跟据(1)的描述可以很快地写出其Matlab代码:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function b = signed2unsigned(a,wl);
%This function covert an signed integer number into an unsinged integer
%number. a is the input vector while wl means the width of input number;
%Example: a = [-2,-1,0,1];
%signed2unsigned(a,3); THEN return [2,3,0,1]
k = 2^(wl)*(a<0);
b = k + a;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%