Line 201... |
Line 201... |
alu_opcode = CLD_IMP;
|
alu_opcode = CLD_IMP;
|
@(negedge clk);
|
@(negedge clk);
|
alu_status_expected[D] = 0;
|
alu_status_expected[D] = 0;
|
check;
|
check;
|
|
|
// SBC BCD
|
|
// LDA
|
|
alu_a = 0;
|
|
alu_opcode = LDA_IMM;
|
|
//$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
|
|
//$display("op1 = %d op2 = %d c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
|
|
@(negedge clk);
|
|
alu_result_expected = 8'h00;
|
|
// NV1BDIZC
|
|
alu_status_expected[N] = 0;
|
|
alu_status_expected[Z] = 1;
|
|
check;
|
|
// SED
|
|
alu_opcode = SED_IMP;
|
|
$display("A = %h B = %h X = %h Y = %h", alu_result, alu_a, alu_x, alu_y);
|
|
@(negedge clk);
|
|
alu_status_expected[D] = 1;
|
|
check;
|
|
|
|
// ADC
|
|
alu_opcode = SBC_IMM;
|
|
for (i = 0; i < 1000; i = i + 1)
|
|
begin
|
|
alu_a = $random;
|
|
$display("A = %h B = %h C = %b X = %h Y = %h", alu_result, alu_a, alu_status_expected[C], alu_x, alu_y);
|
|
@(negedge clk);
|
|
C_temp = 0;
|
|
sign = alu_a[7];
|
|
AL = alu_a[3:0];
|
|
AH = alu_a[7:4];
|
|
BL = ~alu_result_expected[3:0];
|
|
BH = ~alu_result_expected[7:4];
|
|
/*
|
/*
|
if (AL > 9) begin
|
// SBC BCD
|
AL = AL - 10;
|
// LDA
|
AH = AH + 1;
|
alu_a = 0;
|
|
alu_opcode = LDA_IMM;
|
|
//$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
|
|
//$display("op1 = %d op2 = %d c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
|
|
@(negedge clk);
|
|
alu_result_expected = 8'h00;
|
|
// NV1BDIZC
|
|
alu_status_expected[N] = 0;
|
|
alu_status_expected[Z] = 1;
|
|
check;
|
|
// SED
|
|
alu_opcode = SED_IMP;
|
|
$display("A = %h B = %h X = %h Y = %h", alu_result, alu_a, alu_x, alu_y);
|
|
@(negedge clk);
|
|
alu_status_expected[D] = 1;
|
|
check;
|
|
|
|
// SBC
|
|
alu_opcode = SBC_IMM;
|
|
for (i = 0; i < 1000; i = i + 1)
|
|
begin
|
|
alu_a = $random;
|
|
$display("A = %h B = %h C = %b X = %h Y = %h", alu_result, alu_a, alu_status_expected[C], alu_x, alu_y);
|
|
@(negedge clk);
|
|
C_temp = 0;
|
|
sign = alu_a[7];
|
|
AL = alu_a[3:0];
|
|
AH = alu_a[7:4];
|
|
BL = ~alu_result_expected[3:0];
|
|
BH = ~alu_result_expected[7:4];
|
|
|
|
//$display("AL = %h BL = %h", AL, BL, );
|
|
temp1 = AL + BL + alu_status_expected[C];
|
|
//AH = A[7:4] + alu_a[7:4];
|
|
temp2 = AH + BH;
|
|
//$display("temp1 = %h temp2 = %h", temp1, temp2);
|
|
if (temp1 > 9) begin
|
|
temp2 = temp2 + (temp1 / 10);
|
|
temp1 = temp1 % 10;
|
end
|
end
|
if ( AH > 9 ) begin
|
if (temp2 > 9) begin
|
AH = AH - 10;
|
alu_status_expected[C] = 1;
|
C_temp = 1;
|
temp2 = temp2 % 10;
|
end
|
end
|
if (BL > 9) begin
|
else begin
|
BL = BL - 10;
|
alu_status_expected[C] = 0;
|
BH = BH + 1;
|
|
end
|
end
|
if ( BH > 9 ) begin
|
//$display("bcdh2 = %d", bcdh2);
|
BH = BH - 10;
|
//$display("bcdl = %d", bcdl);
|
C_temp = 1;
|
alu_result_expected = {temp2[3:0],temp1[3:0]};
|
|
//{C_in,alu_result_expected[3:0]} = AL + BL + alu_status_expected[C];
|
|
//{alu_status_expected[C],alu_result_expected[7:4]} = AH + BH + C_in;
|
|
//if ( alu_result_expected[3:0] > 9 ) begin
|
|
// alu_result_expected[3:0] = alu_result_expected[3:0] - 10;
|
|
// alu_result_expected[7:4] = alu_result_expected[7:4] + 1;
|
|
//end
|
|
//if ( alu_result_expected[7:4] > 9 ) begin
|
|
// alu_result_expected[7:4] = alu_result_expected[7:4] - 10;
|
|
// alu_status_expected[C] = 1;
|
|
//end
|
|
alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
|
|
alu_status_expected[N] = alu_result_expected[7];
|
|
alu_status_expected[V] = ((alu_a[7] == sign) && (alu_a[7] != alu_result_expected[7]));
|
|
check;
|
end
|
end
|
|
//$stop;
|
|
// CLD
|
|
alu_opcode = CLD_IMP;
|
|
@(negedge clk);
|
|
alu_status_expected[D] = 0;
|
|
check;
|
*/
|
*/
|
|
|
//$display("AL = %h BL = %h", AL, BL, );
|
|
temp1 = AL + BL + alu_status_expected[C];
|
|
//AH = A[7:4] + alu_a[7:4];
|
|
temp2 = AH + BH;
|
|
//$display("temp1 = %h temp2 = %h", temp1, temp2);
|
|
if (temp1 > 9) begin
|
|
temp2 = temp2 + (temp1 / 10);
|
|
temp1 = temp1 % 10;
|
|
end
|
|
if (temp2 > 9) begin
|
|
alu_status_expected[C] = 1;
|
|
temp2 = temp2 % 10;
|
|
end
|
|
else begin
|
|
alu_status_expected[C] = 0;
|
|
end
|
|
//$display("bcdh2 = %d", bcdh2);
|
|
//$display("bcdl = %d", bcdl);
|
|
alu_result_expected = {temp2[3:0],temp1[3:0]};
|
|
//{C_in,alu_result_expected[3:0]} = AL + BL + alu_status_expected[C];
|
|
//{alu_status_expected[C],alu_result_expected[7:4]} = AH + BH + C_in;
|
|
//if ( alu_result_expected[3:0] > 9 ) begin
|
|
// alu_result_expected[3:0] = alu_result_expected[3:0] - 10;
|
|
// alu_result_expected[7:4] = alu_result_expected[7:4] + 1;
|
|
//end
|
|
//if ( alu_result_expected[7:4] > 9 ) begin
|
|
// alu_result_expected[7:4] = alu_result_expected[7:4] - 10;
|
|
// alu_status_expected[C] = 1;
|
|
//end
|
|
alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
|
|
alu_status_expected[N] = alu_result_expected[7];
|
|
alu_status_expected[V] = ((alu_a[7] == sign) && (alu_a[7] != alu_result_expected[7]));
|
|
check;
|
|
end
|
|
//$stop;
|
|
// CLD
|
|
alu_opcode = CLD_IMP;
|
|
@(negedge clk);
|
|
alu_status_expected[D] = 0;
|
|
check;
|
|
|
|
// ASL
|
// ASL
|
alu_opcode = ASL_ABS;
|
alu_opcode = ASL_ABS;
|
for (i = 0; i < 1000; i = i + 1)
|
for (i = 0; i < 1000; i = i + 1)
|
begin
|
begin
|
alu_a = i;
|
alu_a = i;
|