Line 107... |
Line 107... |
alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
|
alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
|
alu_status_expected[N] = alu_result_expected[7];
|
alu_status_expected[N] = alu_result_expected[7];
|
alu_status_expected[V] = ((alu_a[7] == sign) && (alu_a[7] != alu_result_expected[7]));
|
alu_status_expected[V] = ((alu_a[7] == sign) && (alu_a[7] != alu_result_expected[7]));
|
check();
|
check();
|
end
|
end
|
/*
|
|
// 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;
|
|
@(negedge clk);
|
|
alu_status_expected[D] = 1;
|
|
check();
|
|
|
|
// ADC
|
// BCD
|
alu_opcode = ADC_IMM;
|
// LDA
|
for (i = 0; i < 1000; i = i + 1)
|
alu_a = 0;
|
begin
|
alu_opcode = LDA_IMM;
|
alu_a = $random;
|
//$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
|
@(negedge clk);
|
//$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);
|
$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
|
@(negedge clk);
|
$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
|
alu_result_expected = 8'h00;
|
$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], DUT.result);
|
// NV1BDIZC
|
sign = alu_result_expected[7];
|
alu_status_expected[N] = 0;
|
AL = alu_a[3:0];
|
alu_status_expected[Z] = 1;
|
AH = alu_a[7:4];
|
check();
|
BL = alu_result_expected[3:0];
|
// SED
|
BH = alu_result_expected[7:4];
|
alu_opcode = SED_IMP;
|
if ( AL > 9 ) begin
|
@(negedge clk);
|
AL = AL - 10;
|
alu_status_expected[D] = 1;
|
AH = AH + 1;
|
check();
|
end
|
|
if (AH > 9) begin
|
// ADC
|
AH = AH - 10;
|
alu_opcode = ADC_IMM;
|
end
|
for (i = 0; i < 1000; i = i + 1)
|
if ( BL > 9 ) begin
|
begin
|
BL = BL - 10;
|
alu_a = $random;
|
BH = BH + 1;
|
@(negedge clk);
|
end
|
$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
|
if ( BH > 9 ) begin
|
$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
|
BH = BH - 10;
|
$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], DUT.result);
|
end
|
sign = alu_result_expected[7];
|
{C_in,alu_result_expected[3:0]} = AL + BL + alu_status_expected[C];
|
AL = alu_a[3:0];
|
{alu_status_expected[C],alu_result_expected[7:4]} = AH + BH + C_in;
|
AH = alu_a[7:4];
|
if ( alu_result_expected[3:0] > 9 ) begin
|
BL = alu_result_expected[3:0];
|
alu_result_expected[3:0] = alu_result_expected[3:0] - 10;
|
BH = alu_result_expected[7:4];
|
alu_result_expected[7:4] = alu_result_expected[7:4] + 1;
|
if ( AL > 9 ) begin
|
end
|
AL = AL - 10;
|
if ( alu_result_expected[7:4] > 9 ) begin
|
AH = AH + 1;
|
alu_result_expected[7:4] = alu_result_expected[7:4] - 10;
|
end
|
alu_status_expected[C] = 1;
|
if (AH > 9) begin
|
end
|
AH = AH - 10;
|
alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
|
end
|
alu_status_expected[N] = alu_result_expected[7];
|
if ( BL > 9 ) begin
|
alu_status_expected[V] = ((alu_a[7] == sign) && (alu_a[7] != alu_result_expected[7]));
|
BL = BL - 10;
|
check();
|
BH = BH + 1;
|
end
|
end
|
*/
|
if ( BH > 9 ) begin
|
|
BH = BH - 10;
|
|
end
|
|
{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
|
|
|
|
|
// 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
|